Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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

0
THANK YOU THANK YOU THANK YOU THANK YOU!!!!!!!!!!!!!!!! Unbunn_makes 48 — 6y
Ad

Answer this question