What is wrong with this node? get_node: Node not found: HUD.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Neosss

I want to press a button to set the value of a variable in other script and and execute an order on depending on the value it returns.

For this I have used the following script

player.gd

var difficulty = get_node(“HUD”).get(“NormalMode”).difficulty

But Godot says: Node not found: HUD.

I try with other paths like (“Main/HUD”), (“root/Main/Hud”), (“/root/Main/Hud”), (“/Main/Hud”), (“…/HUD”), (“/HUD”).

But always says that the node cannot be found or that absolute paths cannot be used

Mi Project Tree is this

Main.tscn is in the same folder of HUD.tscn

What it’s wrong?
I must say that I have the exact same route Nodes as in the example game Dodge the Creeps

:bust_in_silhouette: Reply From: Neosss

The solution in case someone has the same problem is use the onready before the variable since it is not in any function

Thus remaining the code finally:

onready var difficulty = get_tree().get_root().get_node("Main/HUD").get("NormalMode").difficulty