Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why Does Health Bar Not Update?

Basically this script is suppose to update the players health bar as their health changes. It works fine at first but whenever the player dies and respawns, the bar and text don't update. The text will just state "0/100" and the bar doesn't appear.

local function update()
    local health = hum.Health
    script.Parent:TweenSize(UDim2.new((health / hum.MaxHealth), .3, 1, 1), "Out", "Sine", .5)
    script.Parent.Parent.Amount.Text = math.floor(hum.Health).. " / ".. hum.MaxHealth
end

hum:GetPropertyChangedSignal("Health"):Connect(function()
    update()
end)

2 answers

✓ Accepted answer

Try relocating the script inside of the gui for the health bar (if it isnt already), then enable the gui to reset on spawn.

1 comment

0

For some reason I didn't have the UI set to "ResetOnSpawn" that seemed to have fixed it. Thanks.

Most likely it is bc you put this script in StarterPlayerScripts i suggest you move it into StarterCharacterScripts so when the character dies the player gets a new one and it will receive a new copy of this script so that the currently referenced humanoid is always the one the player is using

This discussion is preserved as it was. New answers, comments, and votes are closed.