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

How to run a while true loop after the condition changes?

The following script only prints twice. I believe this is because once the condition is no longer met the loop no longer runs even when the condition is correct again.



x = false

while x == false do
	print("x is false")
	wait(1)
	x = true
end

while x == true do
	print("x is true")
	wait(1)
	x = false
end

My question is what would be the solution to make this go on forever? (as in printing x = true then x = false repeatedly instead of just once.)

The application which I am using it for is a game loop, but this shows the issue I am facing on a smaller scale.

1 answer

✓ Accepted answer

Hey. If I see that correctly, you are trying to loop something. I would try to do it with a While true do.

My version of the script:

while true do
	x = false
	 
	while x == false do
	    print("x is false")
	    wait(1)
	    x = true
	end
	 
	while x == true do
	    print("x is true")
	    wait(1)
	    x = false
	end
end

1 comment

0

Just tested it, worked fine for me.

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