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

Are ROBLOX events the same as having a different coroutine?

ROBLOX events connect to functions that seem to run on a separate thread. I know everything takes turns running, but this seems a lot like how ROBLOX's scheduler works. For example, if I were to create an event:

player.Chatted:connect(function()
	while wait(1) do
		print("Individual task")
	end
end)

Every time the player chats, it's not yielding in the thread it was created in. Coroutines work the same way, are these two things related at all?

1 comment

0

No, I don't think so. Coroutines make a new thread, so do events, except you have more customization with coroutines.

1 answer

✓ Accepted answer

Yes, ROBLOX creates it's "threads" using coroutines.

Here is a related answer I wrote recently..

wait invokes coroutine.yield and also does some accounting in the engine. ROBLOX automatically coroutine.resumes the thread when it is time for it to run again.

Because ROBLOX does this behind-the-scenes accounting, it's unwise for you to actually use coroutine. methods on "threads"; mixing the two might get you unexpected results.


When an event fires, a new coroutine is made and queued up to handle that event.

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