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

Could someone explain coroutines to me, and maybe give an example?

If you could, that'd be great! (I want to know to further my knowledge and in the end help more people here. If anyone knows how to explain it, please do!)

1 answer

✓ Accepted answer

A coroutine is essentially a new thread within a script. This allows you to have multiple loops at the same time and to continue a script while also yielding, amongst other things. For example:

local loop = coroutine.create(function()
    while true do
       wait()
       print("Hello")
    end
end)
coroutine.resume(loop)
while wait() do
    print("World!")
end
--Both loops here would run simultaneously 

1 comment

0

Thanks for this, and ESPECIALLY for the link. You well deserve the Community Mod rank.

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