Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

Does coroutine.running() ever return nil?

Asked by 9 years ago

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

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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.

Ad

Answer this question