for q=1,100 do wait() print(q*2) end for i=1,200 do wait() if not i%2 == 0 then print'not EVEN close' --I know, not very punny, oops, funny end end
What's going to happen is the first loop is going to run, and then once it's over, the next loop will run. The only way(in my mind) is to make a separate script for the second loop. But i need 6 loops to run at the same time, and I don't want 6 scripts appearing whenever the round restarts(i need 6 loops to run when the round restarts for various purposes). So how can i get 6 loops to run at the same time in the same script?
I'd say you have to make it so something triggers them with a function, that's how I'd do it at least.
--Example idea game.Workspace.ChildAdded:connect(function() for q=1,100 do wait() print(q*2) end end) game.Workspace.ChildAdded:connect(function() for i=1,200 do wait() if not i%2 == 0 then print'not EVEN close' --I know, not very punny, oops, funny end end end)
You can use spawn. This will cause the function you give it as an argument to run separate from the rest of the script (although it's actually much more complex than that, read the wiki about it if you want). This allows you to run two loops at the same time.
function loop() for i = 10,20 do wait(1) print(i) end end spawn(loop) for i = 1,10 do wait(1) print(i) end
You can also use coroutines to get a similar effect. The wiki has pretty much your exact example on it, so I won't bother writing one.
use coroutine, it lets you run more than 1 things on a script: http://wiki.roblox.com/index.php?title=Function_dump/Coroutine_manipulation
coroutine.resume(coroutine.create(function() --the script will be running both this and the other loop at the same time for q=1,100 do wait() print(q*2) end end)) for i=1,200 do wait() if not i%2 == 0 then print'not EVEN close' --I know, not very punny, oops, funny end end
and you could do:
coroutine.resume(coroutine.create(function() for q=1,100 do wait() print(q*2) end end)) coroutine.resume(coroutine.create(function() --now both loops are in a coroutine, so if you added anything else it would run both loops and whatever other code you put for i=1,200 do wait() if not i%2 == 0 then print'not EVEN close' --I know, not very punny, oops, funny end end end))
And if you need to script to run more than 3 things at once you can just add more coroutines!
Recursive solution to making a loop and printing it 100 times
function PrintvalTimes(value) if(value == 0) then --base case print(value); else PrintvalTimes(value-1) end end PrintvalTimes(100)
then if you wanted another loop, just use this function as a model