#Health/progressbar not updating

4 messages · Page 1 of 1 (latest)

marble igloo
#

Hi, i've inserted a progressbar on my player/canvaslayer and attached a script to it, in the script i've got


@export var player: Player

func _ready():
    player.healthChanged.connect(update)
    update()

func update():
    value = player.currentHealth * 100 / player.maxHealth```

in the player script i've got these

signal healthChanged
@export var maxHealth = 100
@onready var currentHealth: int = maxHealth

func _on_hurt_box_area_entered(area):
if area.name == "HitboxComponent":
currentHealth -= 30
healthChanged.emit(currentHealth)
print_debug(currentHealth)```
it does show the damage in the debug window but the bar itself is always on 0%, what have i done wrong here ? i feel like it has to do with the update function but im not sure 😦

marble igloo
#

Health is always at 0 even though the debugger does correctly adjust the hp (100-70-40 etc) when i run into a mob. when i comment out the update function the healthbar does go to 100% but doesn't update a hit.

hushed heron
#
  • If you print value at the end of update() does it stay at zero?
  • Does updating value constantly in func _process(_delta) work?
  • Are you sure the player is pointing to the actual player?

Mind showing your scene tree showing where player is in relation to health bar?
Also, a screenshot of your progress bar's settings in the inspector?

marble igloo
#

Thanks for the reply, if i print the value i get this

it does seem to work properly if i use _process(_delta), I'm not 100% sure what you mean with #3 but my script is called Player.gd, class_name Player