Do spawn(), wait() and delay() work using coroutines?

I have read many times this tutorial (Beginners Guide to Coroutines) but I still can’t understand it completely. Please could someone explain to me what this sentence means?

…the functions spawn(), wait(), and delay(). These actually work using coroutines.

Yeah they work within coroutines. That sentence means they utilize coroutines internally.

2 Likes

So, for example, when I use wait a coroutine is created internally?

Not quite, what happens is the coroutine that wait was called in is suspended.
An over-simplified explanation of what’s going on:

  • Each script is executed with their own coroutine
  • When the script calls a yield function (like wait, etc.) the coroutine is suspended to be later resumed by Roblox.
  • When a script calls spawn/delay, a new coroutine is created.
1 Like

You know, I don’t think that’s actually correct. I’m fairly positive that coroutines, being native Lua, are run separately from wait/spawn/delay, which all use Roblox’s task scheduler.
This page backs up my statement, heavily implying that wait/spawn/delay are separate from coroutines.

Avoid using while wait() do end or while true do wait() end constructs, since these aren’t guaranteed to run exactly every frame or gameplay step. Instead, use events like Stepped or Heartbeat .
Similarly, avoid using spawn() or delay() as they use the same internal mechanics as wait() . Uses of spawn() are generally better served with coroutine.wrap() and coroutine.resume() of the coroutine library.

They are not separate, the task scheduler also resumes coroutines.
In the same page you linked, it’s described here "