Updating text when a button is pressed

Godot Version

4.6

Question

as the title says I'm trying to have text change when a button is pressed specifically when the button is pressed the number displaced on a label decreases, the issue is though when I actually press the button in the game it crashes and I receive the error "Invalid assignment of property or key ‘text’ with value of type ‘String’ on a base object of type ‘null instance’.”
this is the current code I’m using

func _on_button_pressed():
var my_label = $Label
my_label.text = “whatever I want”

it comes from me looking at a 6yr old reddit comment and what google ai popped up with.
thanks in advance for any help

The error means that my_label is null. Since you initialize it directly with a node path, it must be that the path in incorrect.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.