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

Why is my Health GUI not updating in game?

Asked by 7 years ago

Hi guys, so I have this local script which I put in a GUI, It is a health GUI. It seems to be working fine in Studio but it doesn't work when I try it in game.

player = game.Players.LocalPlayer
Character = player.Character
Humanoid = Character:WaitForChild("Humanoid")

GUI = script.Parent
HealthGUI = GUI:WaitForChild("Maxhealth")
MaxhealthGUI = HealthGUI:WaitForChild("Health")

while true do
    local Value
    local Percentage = (math.abs(Humanoid.Health-Humanoid.MaxHealth))/Humanoid.MaxHealth

    if Humanoid.Health > 100 then
        Value = 1
    else
        Value = 1 - Percentage
    end 

    MaxhealthGUI:TweenSize(UDim2.new(Value,0,1,0))
    wait()
end

It updates every time a person dies but then stops working again. So can anyone help?

0
'Humanoid' would be nil when they die User#5423 17 — 7y
1
No, Humanoid would still exist but have its Health set to 0. Try adding wait(1) at the top of the script, this sounds like a replication issue einsteinK 145 — 7y
1
You should use .changed instead so you can make a function after that because i fyou use a a while true do the loop with not get past it because it cannot break ZeonMaxwelll 75 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

I don't know what's wrong, I tested it and it worked for me. Try opening output and adding some prints in there.

Ad

Answer this question