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
'Humanoid' would be nil when they die
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
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