Label text not updating and erroring instead

Godot Version

godot 4.3

Question

Invalid assignment of property or key ‘text’ with value of type ‘String’ on a base object of type ‘null instance’.
this is being returned when i run this code:
‘’‘func money_add(newmoney):
money += newmoney
$GUI/Balance.text = str(money)’‘’
the function is in an autoload and is called by instances that needs to update the players money
label in the gui before disappearing. The path should be correct as i have replaced it multiple times and not changed the location of it

Clearly the path is incorrect…

the function is in an autoload

…because the script is in an autoload. This puts it in the SceneTree, unlikely that the $GUI/Balance NodePath resolves to anything beneath it the autoload; you can verify this in the Remote tab when debugging.

As an alternative, consider using signals to update the label instead.

1 Like

Is the GUI a child of the autoload? If it is, did you add the .tscn file as an autoload or just the .gd file?