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

How can you start a loop with a code block?

What is the code for starting/ending a loop?

2 answers

✓ Accepted answer
number = 1

while true do
wait(1)
number = number + 1
if number == 5 then
	break
end
end

1 comment

0

Thanks!

There are multiple ways of creating a loop, here are some:

-- Simply every 1 second, 'loop' is printed in the output, this loop is continuous

while true do -- while loop
wait(1) -- waits 1 second
print("loop") -- outputs
end -- ends
-- For loop that counts down from 30, when it hits 0; it ends

Count = 30 -- 30 second

for i = Count, 0, - 1 do -- for loop, loops for 30 seconds
print(i)

-- simple if statement to end the loop when it gets to 10 seconds, you could do this for rounds, etc if you made a game
if i == 10 then
print("round end?")
break -- pretty much destroys the loop / stops the loop
end

end
-- Loops every 1 second, the rest should be pretty self explanatory

while wait(1) do -- while wait() loop
print("hi")
end

1 comment

0

If you have any problems, let me know.

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