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

Which code do I use to make my script loop forever?

What's the code snippit I use to make my script loop forever? I'm making a button change colors... :P

3 answers

✓ Accepted answer

Most common way is to use a while loop A while (statement) do look is the most common ways to make a loop that continues on forever and ever unless you can possible use a break to end the endless loop.

An example:

while true do
	--Code
end

Another way to use a while loop is with a boolean statement such as..

while 5 < 9 do
	--Code
end

That basically does the same thing, but it runs if 5 is less the 9, if you where to put while 5 > 9 do, that wouldn't run the loop since 5 is not greater than 9.

Another common loop is a for loop, which runs a command a certain number of times, an example:

for i = 1, 10 do
	print("Hello world!") --Put your code
end

Which would print in output "Hello world!" ten times, 1 being the first, and 10 being the end. Think of the comma as the word "to", so it prints "Hello world!" once, then again, and again and so on until it has been printed 10 times. (Same if you replaced it with your code)

You'd use a while loop, although I'd discourage it for what you're doing.

while true do
	-- code
	-- make sure you have wait
end

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