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 used for and how do i make one?

What is coroutine used for and how do i make one?

1 comment

0

Just so you know: Coroutines are only infrequently the right choice

2 answers

It's as if the script were saying, "Go on, I got this."

When you create a coroutine, it creates another thread, inside this thread you will have your code, whatever it may be. However, while this code is running inside the coroutine, the script continues on and runs the rest of the script. For example:

coroutine.wrap(function()
	while wait(1) do
		print("Hi, I'm doing my own thing!")
	end
end)()

print("Bye, I'm off to more important things!")

And that would print, "Hi, I'm doing my own thing!" once every second, but also print, "Bye, I'm off to more important things!" at the same time.

Hope that helped.

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