I have a for loop looking like this: for i = 90,1,-1 do The for loop is inside a while true do loop When I use break to stop the for loop its stops it after while true do repeats How can I make the for loop stop but when the while loop starts it will work again? Can anyone help me out?
How do I stop a for i = 90,1,-1 do loop that's inside a while true do loop?
1 answer
Using break will exit the current loop.
Also, you could set a variable and check if that variable is true before running your loop so you can control whether it will run or not.
local runForLoop = true
while true then
if runForLoop then
for i = 90, 1, -1 do
if i == 45 then
runForLoop = false
break
end
end
end
wait()
end
The script above will set runForLoop to false and stop running the loop when i is 45.
If you want the for loop to start working again, simply set runForLoop to true.
4 comments
Doesn't that stop the run WhileLoop? I only want to stop the for loop once anw when the while loop repeats it works again.
Okay, I edited my script. This should be what you're looking for.
If runForLoop is ever false, there will be an infinite while loop with no waits.
I was assuming he has a wait, and other stuff inside the while loop otherwise he would've gone with my initial solution.
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
You can use the syntax break. This stops a loop
Did you read the details? When I use break it stops it and when the while true do loop starts again it wont work.
@saSlol2436 "When I use break to stop the for loop its stops it after while true do repeats How can I make the for loop stop but when the while loop starts it will work again?"
I didn't notice. Sorry for disturbing you
This sounds like an XY problem to me. http://xyproblem.info/