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

How do I stop a for i = 90,1,-1 do loop that's inside a while true do loop?

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?

5 comments

0

You can use the syntax break. This stops a loop

0

Did you read the details? When I use break it stops it and when the while true do loop starts again it wont work.

0

@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?"

0

I didn't notice. Sorry for disturbing you

1

This sounds like an XY problem to me. http://xyproblem.info/

1 answer

✓ Accepted 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

0

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.

0

Okay, I edited my script. This should be what you're looking for.

0

If runForLoop is ever false, there will be an infinite while loop with no waits.

1

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.