I always got this error:

Invalid set index 'text' (on base: 'null instance') with value of type 'String'.

I tried a lot of things the location is ok

This it the structure

Popup (node type: Popup)
├── AnimationPlayer (node type: AnimationPlayer)
├── Timer (node type: Timer)
└── Box (node type: Panel container)
└── Label (node type: Label)

func show_popup(msg: String) -> void:
	%PopUp/Box/Text.text = msg
	%PopUp/AnimationPlayer.play("Show")
	%PopUp/Timer.wait_time = 2
	%PopUp/Timer.start()

    That error means it can't find the node you're trying to set text for,

    foxycodes └── Label (node type: Label)

    shouldn't it be %PopUp/Box/Label.text = msg instead of %PopUp/Box/Text.text = msg ?

      housatic No, It was my mistake cuz the label is named Text so it should not be like that. Idk everything looks fine and right.

        foxycodes The "%PopUp/Box/Text" too? you don't have the label inside "Box" in your structure

        foxycodes In your hierarchy, Text(Label) is not a child of Box, but your code tries to access it like it is.

          xyz Oh Im stupid the hierarchy is made not by me and its wrong here are the corrected one


          The popup scene

          _

          Main scene

          <

          Script

          foxycodes If script is in PopUp then the relative path to label node would be $Box/Text

            xyz No there is script in the main scene and the Popup scene is in the main scene

            • xyz replied to this.

              foxycodes Where exactly is the script? To which node it's attached?

              kuligs2 % is used for unique nodes, it is for use with a single node that must act as a singleton but not be an autoload.

              retrieving nodes with % and $ is bad practice and mostly used for teaching.
              using $ in a scene that will be instantiated is ok, because the tree is not prone to change and the nodes are local, but it's usage must be reduced by the use of references and methods because it means that if the node structure is changed, only one line of code has to be edited, instead of having to search through the script to replace each usage.

              using $label is the equivalent of doing get_node("label"), so it's best to only do it once in ready or onready