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

Why is my Health GUI not updating in game?

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?

3 comments

0

'Humanoid' would be nil when they die

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

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

1 answer

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

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