HUD values are not updated

Godot Version

4.4.1

Question

I have created a HUD node. There are labels with default values there. The default value for coin counter is 0.
In the script ralated to the HUD node I have created a function to update the score once the character picks up a coin:

extends CanvasLayer

var score = 0
var hp = 3
@onready var coin_score_label: Label = $"coin score/coin score label"
@onready var hp_label: Label = $"hp/hp label"

func add_point():
	score += 1
	coin_score_label.text = str(score)
	
func take_damage():
	hp -= 1
	hp_label.text = str(score)

add_point function is used in the script the the Coin object

extends Area2D

@onready var hud: CanvasLayer = %HUD
@onready var animation_player: AnimationPlayer = $AnimationPlayer

func _on_body_entered(body):
	hud.add_point()
	animation_player.play("pickup")

The problem is that the default 0 value is still there and it is not overwritten by the above steps.
image

Also HUD is added ot the Autoload menu for the project

Autoload adds the scene/script to the game while running, if you already have a hud scene in your scene tree then you will have two huds. You can access the autoload with the set global name, or you could remove the autoload, since your code seems to be working wtih %HUD on it’s own.

1 Like

Ah, my bad!!!
Thank you very much!