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

Does coroutine.running() ever return nil?

According to the wiki, it returns "nil when called by the main thread."

What is this main thread?

ex. When I call "coroutine.running()" in the body of a script, it returns a non-nil result.

I have a function that yields the currently running thread, but it won't work if the current coroutine is "nil". Will this ever happen in practice?

1 answer

✓ Accepted answer

That line in particular comes from PIL 5.1:

Returns the running coroutine, or nil when called by the main thread.

http://www.lua.org/manual/5.1/manual.html#pdf-coroutine.running

Since this doesn't return nil, it means that no Script has the main thread.

This should be expected, because, for example, Disabled will make scripts stop at the next yield, and re-enabling them will resume them; further, you can use wait and friends which also yield the thread.

The "main thread" is likely hidden somewhere by ROBLOX.

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