So I got the main part of the script from the usual ROBLOX Health script and added to make sure the stats for water and food is greater than 0.
if Food.Value > 0 and Water.Value > 0 then while Humanoid.Health < Humanoid.MaxHealth do if Food.Value > 0 and Water.Value > 0 then local E = wait(1) local Health = Humanoid.Health local MaxHealth = Humanoid.MaxHealth if Health > 0 and Health < MaxHealth then local AddedHealth = 0.01 * E * MaxHealth Health = Health + AddedHealth Humanoid.Health = math.min(Health, Humanoid.MaxHealth) end end end if Humanoid.Health > Humanoid.MaxHealth then Humanoid.Health = Humanoid.MaxHealth end Regening = false end
When I test it and the food and water runs out, the game stops responding. Any ideas?
Your wait() is only effective if your food and water are at more than 0. Just go ahead and put a wait() right after your loop is called.
The wait()
function is very important when using a loop
, This prevents game crashes
. You can place you wait() function in your loop or next to the condition, example. while condition and wait() do return true end
or while true do; wait(); end