Why doesn't Humanoid.HealthChanged work after death?
In my game, I have a health bar BillboardGui. Here is the hierarchy. So here is the code in the Script:
01 | repeat wait() until script.Parent.Parent.Parent.Name = = "Head" |
02 | local char = script.Parent.Parent.Parent.Parent |
03 | local h = char.Humanoid |
04 | local max = h.MaxHealth |
05 | local f = script.Parent |
07 | script.Parent.PlayerName.Text = char.Name |
08 | script.Parent.Parent.Adornee = char.Head |
10 | h.HealthChanged:connect( function () |
11 | bar:TweenSize(UDim 2. new( 0.9 / max * h.Health, 0 , 0.4 , 0 ), "Out" , "Bounce" , 1 ) |
13 | if h.Health > ( 3 / 5 * max) then |
14 | f.Bar.BackgroundColor 3 = Color 3. new( 0 , 255 , 0 ) |
16 | if h.Health < = ( 3 / 5 * max) then |
17 | f.Bar.BackgroundColor 3 = Color 3. new( 255 , 255 , 0 ) |
19 | if h.Health < = ( 2 / 5 * max) then |
20 | f.Bar.BackgroundColor 3 = Color 3. new( 255 , 141 , 1 ) |
22 | if h.Health < = ( 1 / 5 * max) then |
23 | f.Bar.BackgroundColor 3 = Color 3. new( 255 , 0 , 0 ) |
My problem is this: when the player dies, the health bar goes to zero. That's good. However, what's not good is that after the player dies, the health bar doesn't go back up to 100. Instead, it stays red and at zero. Why is this so, and how can I fix this? I have a theory already that it's because every time the player dies, the Humanoid is removed, but I don't know how to get around this.