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!”)
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:
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!”)
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.