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

Why does this script stop looping, do I need to put an else?

I want to make this script stop working when the generators health is less than 10000. The script works but when the health of the generator changes and isn't 10000 the script dosen't stop? Solutions.

while game.Workspace.Generator.Generator.Health == 10000 do
        wait(40)
		script.Parent.Text = "20"
		wait(1)
		script.Parent.Text = "19"
		wait(1)
		script.Parent.Text = "18"
end

2 comments

0

Try Humanoid.Health

0

I renamed the humanoid

3 answers

✓ Accepted answer

Your script don't stops because you don't break it, and you change the value while the while loop is still running, you can try this to avoid:

(I just made the run time of the while loop lots smaller, so it checks the condition more times)

wait(40)
while game.Workspace.Generator.Generator.Health == 10000 do
        wait(1)
        script.Parent.Text = tostring(tonumber(script.Parent.Text) - 1)
end

3 comments

0

Thx ill try it

0

I tried it with a small script and it worked however the script i'm using is 2000 lines long is there a way to make the while true loop every second

0

this while loop runs every second, if you want, remove the wait(40)

You could try to break the loop instead.

while game.Workspace.Generator.Generator.Health == 10000 do -- you could change this to while true do now if you'd like since we're breaking the loop at the end when the if statement is met
        wait(40)
        script.Parent.Text = "20"
        wait(1)
        script.Parent.Text = "19"
        wait(1)
        script.Parent.Text = "18"

end

3 comments

0

thx ill try it

0

Will also error

0

Sorry it didn't work

It literally checks if it is equal. If it is not it stops. Just check if 10000 is more by using more or equal.

while game.Workspace.Generator.Generator.Health <= 10000 do
        wait(40)
        script.Parent.Text = "20"
        wait(1)
        script.Parent.Text = "19"
        wait(1)
        script.Parent.Text = "18"
end

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