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

Is there a way to run two loops(repeat loops or while true do loops) inside a script?

I've tried to use a module script and it didn't work, because it was practically the same thing as adding it to the script itself. I want to know if there's a method to run two separate loops (repeat loops or while true do loops) inside of a script for example:

If I do this it will run the other loop after the loop above it ends.

local b = false

while true do
wait(0.1)
print('a')
end 

repeat
wait(0.1)
print('b')
until b == true

If there isn't a way to do this. How would I communicate to another script without firing remote events?

1 answer

✓ Accepted answer

Use spawn(function()

spawn(function() is basically like running two things at the same time, it's very useful, especially if you need to do things after a loop, or two loops. Let me show you how you would do it in this case:

local b = false
spawn(function()

while true do
wait(0.1)
print('a')
end
end) 
spawn(function()
repeat
wait(0.1)
print('b')
until b == true

end)

wiki page: http://wiki.roblox.com/index.php/Thread_scheduler

1 comment

0

THANK YOU THANK YOU THANK YOU THANK YOU!!!!!!!!!!!!!!!!

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