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

[SOLVED] HP Bar works in Studio but not on Play?

Asked by 8 years ago

I made a working health bar that decreases with the player's health, and it works perfectly on Studio, but it does not respond on Play mode. Any ideas what I am doing wrong?

PD : It is under a LocalScript...

Code :

player = game.Players.LocalPlayer
char = player.Character
human = char.Humanoid
HP = script.Parent

while wait() do
    HP:TweenSize(UDim2.new(0, (human.Health*311)/human.MaxHealth, 0, 24))
    if HP.Size.X.Offset <= 165 and HP.Size.X.Offset > 25 then
        HP.BackgroundColor3 = Color3.new(200/255, 200/255, 0)
    else if HP.Size.X.Offset <= 25 then
        HP.BackgroundColor3 = Color3.new(200/255, 0, 0)
    else
        HP.BackgroundColor3 = Color3.new(110/255, 185/255, 20/255)
    end
    end
end

Any help is appreciated!

TheArmoredReaper

0
Is this a local script or a server script? Necrorave 560 — 8y
0
LocalScript under StarterGUI. The output does not give any errors (at least in Studio) TheArmoredReaper 173 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

Already solved it. Had to add a wait() to let the Client get the Character...

Thanks anyway!

0
Good luck with your project! Necrorave 560 — 8y
0
you could also write `player.Character or player.CharacterAdded:wait()` 1waffle1 2908 — 8y
Ad

Answer this question