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

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

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

2 comments

0

Is this a local script or a server script?

0

LocalScript under StarterGUI. The output does not give any errors (at least in Studio)

1 answer

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

Thanks anyway!

2 comments

0

Good luck with your project!

0

you could also write player.Character or player.CharacterAdded:wait()

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