I have a script that changes the text on a health bar to correspond with an HP value, most of the time it works fine but occasionally it bugs out and either doesn't change the text to the new value or changes the text to a value I changed it to previously. If I click onto the text label it updates or something and changes to the correct value. Is this just a visual bug in Studio or is there something wrong with my script?
hpv = script.Parent.Parent.Parent.Parent.Parent.Parent:WaitForChild('ZombieStats'):WaitForChild('HealthPoints')
hpv.Changed:Connect(function()
if hpv.Value > 0 then
script.Parent.Text = (hpv.Value..' HP')
else
hpv.Value = 0
script.Parent.Text = ('0 HP')
end
end)

1 comment
The script below won't cause too much lag as even if it updates every second or so, the values won't change much unless the player is getting anything. Therefore, the code only acts when there is a change in leaderstats or hpv in this case