So if i have a for loop running at the moment, how can i activate another for loop, in that same script, while the other for loop is running?
spawn(function() for i,v in (i)pairs(array) do --// Functionallity end end) for i,v in (i)pairs(array) do --// Functionallity end
Spawn
creates a separate thread for the piece of Lua C to run in, while the rest of the opposite thread is running alongside, being unaffected by the lone program.
on the loop
spawn(function() loop end) meaning it'll run and the script will continue running even if the loop hasn't ended
https://developer.roblox.com/articles/Thread-Scheduler
There are two ways to accomplish this!
1. Create 2 scripts with for loops and activate them both from another script! This obviously isn't ideal, so I would recommend...
2. Include the second for loop in a separate function! Take a look at the example script below:
function secondLoop() --This is the second for loop in a separate function! for j = 1, 10 do print(j) end wait() end for i = 1, 20 do if i == 10 then --This will ONLY fire when i reaches 10, which is about halfway through the script secondLoop() --Now, another for loop has started while this one is running! end print(i) wait() end
This, I would say, is the simplest way to achieve what you're asking for. If you have any questions, please feel free to ask!