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

What is "coroutine" for and what is it useful for?

i never heard of coroutine and im just curios what it does, maybe it can help in the future

1 answer

✓ Accepted answer

coroutine is used to run scripts at the same time (similar to creating a new script in workspace). if you had to run 2 functions at the same time, you could use them for example

coroutine.resume(coroutine.create(function()
	print("Hi")
end))

print("Hi")

They would print both at the same second.

There are more ways to use them, but this is a first way to know their job.

coroutine.create() makes a coroutine, in which you can place code.

coroutine.resume() runs the coroutine, like if you run a normal script by playing the game or pressing a button.

coroutine.wrap() acts like both above

coroutine.yield() yields (pauses/stops) the script

There are more uses for it and more corutine commands, if you want to know more go here: Beginners Guide to Coroutine

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