0 votes

Hello, community. I just started with Godot today.

I'm trying to do as the scripting tutorial says and make it so that "HELLO!" appears when I click the "press me" button while running it, but I keep getting an error message.

The final script is supposed to be this:

extends Panel

func _ready():
    get_node("Button").connect("pressed", self, "_on_Button_pressed")

func _on_Button_pressed():
    get_node("Label").text = "HELLO!"

When trying to run it, this is the error message: Attempt to call function 'connect' in base 'null instance' on a null instance.

Stack frames: 0 - res://Sayhello.gd:4

Members: Self

Under the Errors (1) tab: 0:00:01:0761 - Node not found: Button

Stack Trace (if applicable): _ready in sayhello.gd:line 4

Thank you. I'm happy to be part of this community and to create with Godot :)

in Engine by (12 points)
edited by

1 Answer

0 votes

FYI, I edited your post to fix the code formatting. In future, please make sure to format your code properly so readers can make sense of it.

"null instance" errors almost always are due to node paths used in get_node() being incorrect. Your scene tree should look just like this one:

enter image description here

The script is running on Panel, so get_node("Button") is looking for a child of that node named "Button". It seems that either you've changed the node arrangement or the name of the button node.

by (22,067 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.