Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Game stops responding when food and water runs out?

Asked by 8 years ago

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?

0
Add an wait() function. woodengop 1134 — 8y
0
Where? TypicalModerator 110 — 8y
0
Add a wait below line 11, whereas the while ends before it unmiss 337 — 8y

2 answers

Log in to vote
0
Answered by
saenae 318 Moderation Voter
8 years ago

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.

Ad
Log in to vote
1
Answered by
woodengop 1134 Moderation Voter
8 years ago

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

Answer this question