Trying to hide a label but is not working

Godot Version

4.3

Question

im trying to hide a label when a button is pressed and when it first starts but it gives me an error saying “Attempt to call function ‘hide’ in base ‘null instance’ on a null instance.” im confused, can someone help me?
func _on_touch_screen_button_pressed() → void:
if Global.berry >= 3:
$Sprite2D/Label.hide()
else:
Global.berry += 1
queue_free()

func _on_area_2d_area_entered(area: Area2D) → void:
if area.is_in_group(“Player”):
# enable inputs on enter
set_process_input(true)
print(“Player Entered!”)

func _on_area_2d_area_exited(area: Area2D) → void:
if area.is_in_group(“Player”):
# disable inputs on exit
set_process_input(false)
print(“Player Exited!”)

func _ready() → void:
# disable inputs on start
set_process_input(false)
$Sprite2D/Label.hide()

func _input(event: InputEvent) → void:
# check for “Use”
if event.is_action_pressed(“Use”):
self.queue_free()

That means your node path is wrong, can you show a print of your scene organization?

Screenshot 2024-12-19 171936

Are you using this script somewhere else? Look into the Errors tab, probably you’ll also receive an error about not found the node that also shows where’s failing:

does instantiated objects count?

i only see one error saying it

How you’re instancing the node? Can you show this code?

sure

extends StaticBody2D

@onready var bush = $“.”

func _on_touch_screen_button_pressed() → void:
if Global.berry >= 3:
$Sprite2D/Label.hide()
else:
Global.berry += 1
queue_free()

func _on_area_2d_area_entered(area: Area2D) → void:
if area.is_in_group(“Player”):
# enable inputs on enter
set_process_input(true)
print(“Player Entered!”)

func _on_area_2d_area_exited(area: Area2D) → void:
if area.is_in_group(“Player”):
# disable inputs on exit
set_process_input(false)
print(“Player Exited!”)

func _ready() → void:
# disable inputs on start
set_process_input(false)
$Sprite2D/Label.hide()

func _input(event: InputEvent) → void:
# check for “Use”
if event.is_action_pressed(“Use”):
self.queue_free()

Nowhere in that code do you instantiate anything.
Matheusmdx was asking you to show the code that instiates, not the code that is instatiated.
Also, please use the code tag when posting code. It looks like this </>.
GDScript is indentation based and unformatted code does not retain its indentations.
PS: You can edit your previous posts to fix that formatting.

I just switched the code to the label, and it worked. thanks for responding!

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