I'm trying to make a loop that runs while code after it can still run in the same script. I don't have any code because I don't know what I would do that is why I am asking.
✓ ANSWER ACCEPTED
How do I make code after a loop run while the loop is still going?
1 answer
✓ Accepted answer
Coroutines would do the trick.
Heres a link that will help you understand them better: https://developer.roblox.com/en-us/articles/Beginners-Guide-to-Coroutines
Here's an example:
local countdown = coroutine.wrap(function(time)
while time > 0 do
wait(1)
time = time - 1
end
print("Countdown ended!")
end)
countdown(10)
Now, any code you run before or after the coroutine will not yield.
This discussion is preserved as it was. New answers, comments, and votes are closed.
