Still have questions? Join our Discord server and get real time help.
0

How to do loops? [closed]

How do i do loops for scripting?

Locked by TheeDeathCaster and BlueTaslem

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

5

Loops? Ok.. Here are some example loops (Sorry if didn't help);

repeat until nil


1.This repeats a loop non-stop (see 3 for more information), but if you want it to stop at a certain point;

repeat wait(0)script.Parent.Value=script.Parent.Value+1 until script.Parent.Value=100


2.For this one, It will repeat until the value equals to 100.

3.But if you take away 'script.Parent.Value=100' to 'nil', then the loop will never stop until something other occurs, like an error.

4.There is also while true do end. Like repeat until nil, but a bit different. Here is an example of a while true do end loop;

while true do
wait(0)
print("Everything is awesome!")
end


5.It will repeatedly print Everything is awesome! non-stop until script is removed or disabled. :P

6.But there is a way to break the while true do end loop, add break into the while true do end statement, and this'll happen;

while true do
wait(0)
print("Everything is awesome!")
break
end


7.As you'll see, it'll only print Everything is awesome! once, because break breaks a loop, same with for LOL=1,9 do end

8.Surprized you can use for for a loop? Here is an Example of one;

for i=1,9 do
wait(0)
print("Everything is awesome!")
end


9.As you'll see, it'll print Everything is awesome! 9 times, unless there is a break (see 6 and 7 for more information)

I hope this helped!

1
It would help TheAlphaStigma if you would also up his reputation. Gamenew09 175 — 6y
0
How do i do that? iluvmaths1123 198 — 6y
0
repeat until false seems more canonical BlueTaslem 17977 — 6y
-3
Vividex 162
6 years ago
while true do
--stuff
end