Invalid assignment of property or key 'text' with value of type 'String' on a base object of type 'Nil'

Godot Version

4.0

Question

I am trying to get my game manager nodes function that increases the point anytime the cherry is touched and update the score label but i get this error

Invalid assignment of property or key ‘text’ with value of type ‘String’ on a base object of type ‘Nil’.

Heres my code for the game manager:

extends Node
var points = 0
@export var label :Label

func _ready():
	pass
	
func addPoints():
	points += 1
	print(points)
	label.text = "Hello World"

Here is my Cherry code:

extends Node


func _on_cherry_body_entered(body):
	if body.name == "Player":
		GameManager.addPoints()
		queue_free()

Here is my Node Tree

Is the gamemanager a autoload?

1 Like

Click on your gamemanager node and make sure the label export is set properly

3 Likes

Try , label.modulate to change the text, if I am late I apologize.

I ran into this same issue. Nothing posted here helped me, however when I checked my code one more time I realized I had changed the location of my Label, so my Label import pathing was incorrect. Make sure you redefine it, and I hope that it fixes the problem for you!