Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't Humanoid.HealthChanged work after death?

Asked by 6 years ago

In my game, I have a health bar BillboardGui. Here is the hierarchy. So here is the code in the Script:

01repeat wait() until script.Parent.Parent.Parent.Name == "Head"
02local char = script.Parent.Parent.Parent.Parent
03local h = char.Humanoid
04local max = h.MaxHealth
05local f = script.Parent
06local bar = f.Bar
07script.Parent.PlayerName.Text = char.Name
08script.Parent.Parent.Adornee = char.Head
09wait(1)
10h.HealthChanged:connect(function()
11    bar:TweenSize(UDim2.new(0.9 / max * h.Health, 0, 0.4, 0), "Out", "Bounce", 1)
12 
13    if h.Health > (3/5 * max) then
14        f.Bar.BackgroundColor3 = Color3.new(0, 255, 0)
15    end
View all 25 lines...

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.

0
Try Changed instead of health changed User#19524 175 — 6y
0
@incapaz Changed isn't an event of Humanoid. See this link: https://wiki.roblox.com/index.php?title=API:Class/Humanoid Zenith_Lord 93 — 6y
0
You should disconnect the event adter it reaches 0 User#5423 17 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

I had a really similar issue. And you want to make sure that ResetOnSpawn is ENABLED. If this affects your intro or whatsoever, simply add a LocalScript into StarterCharacter and check if the intro is running, if it is then wait a certain amount of time before continuing, else just make the element visible or enabled the GUI.

This may fix your issue if not please comment.

0
What is ResetOnSpawn and how do I enable it? Zenith_Lord 93 — 6y
0
It's a property in ScreenGui BlackOrange3343 2676 — 6y
0
Even after enabling it for my BillboardGui, http://prntscr.com/jteed5  that's after I reset. Zenith_Lord 93 — 6y
Ad

Answer this question