Health value continuing to change even though math says that it shouldnt?

I have a script which when you level up your maxhealth increases by +4 and on join your maxhealth is changed to whatever your level is*4 but it doesn’t automatically give you the health that you should have which is for example if you are level 50 then your max health would be 300/300 but upon join it is 300/100

This is my script

while wait() do

script.Parent.Humanoid.MaxHealth = 100 + (game.Players[script.Parent.Name].leaderstats.LV.Value * 4)

end

if script.Parent.Humanoid.MaxHealth ~= script.Parent.Humanoid.Health then

script.Parent.Humanoid.Health = script.Parent.Humanoid.MaxHealth

end

The bottom part should only run twice when the player joins but it doesn’t help would be appreciated on why it doesn’t

It doesn’t run because above it you have a while wait() do loop, which is infinite if you don’t break it

Why do you have that infinite loop exactly? Can’t you just WaitForChild the Humanoid and then set its maxhealth?

1 Like