Invalid set index 'text' (on base: 'null instance') with value of type 'String'. please help

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JoseDTD
extends Node2D

# Declare member variables here. Examples:
var points = 0
onready var point_text = $INTERFAZ/Label #variable
func get_axis() -> Vector2:
	var axis = Vector2.ZERO
	axis.x = int(Input.is_action_pressed("ui_right")) - int(Input.is_action_pressed("ui_left"))
	return axis
# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
		point_text.text = "Points: " + str(points)

func _on_Area2D_body_entered(body):
	if == "Player":
		points += 1

Edited to fix forum code formatting…

jgodfrey | 2023-05-27 14:02

:bust_in_silhouette: Reply From: GlitchedCode

Based on the error here, I would assume the declared variable and your $INTERFAZ/Label are not in the same scene initially and the label is instantiated afterwards. The reason I am led to believe this is because the error portion reading back “on base: ‘null instance’” tells me that your variable pointtext is null.

If it is null then either your path is wrong or, you are setting the variable before the node is in the scene which falls back to an invalid path at the time of assignment.

change pointtext.text = "Points: " + str(points)
to $INTERFAZ/Label.text = "Points: " + str(points)

If it works, then this just further confirms my suspicion of the variable being set before the node(s) is in the scene.
If it still does not work, double check your path and spelling both in the code and your scene tree.