Coroutine status is ALWAYS suspended?



I was checking the coroutine status but It’s ALWAYS returning suspended even though it’s running. I’m not sure what is causing this?

running status can only be observed inside the coroutine while it’s executing.

A yielded coroutine’s status will always be “suspended” and will only be “running” during the exact time it’s executing, which is very brief and hard to catch from the outside.

You’ll only ever see “running” if the coroutine status is checked outside the coroutine while it’s executing. Since you’re using waits, you’re going to miss that window.
Here’s a little cheat sheet

Coroutine State | Meaning
“suspended” | Waiting/yielded, ready to resume
“running” | Actively executing (rare to catch)
“dead” | Finished execution or errored

Edit: Just realized this was answered lol

Is there a way to check it ouside of the coroutine? I’m trying to check if my sentry is in idle or not so I can yield the coroutine.

Nobody has really broken this down for you so I’ll give the rundown.

Firstly, you have to remember that Luau (outside of Actors) is going through each task one by one.

So you’ll only see “running” when you call coroutine.status from within the task you are asking the status for.

So for example:

local Idle_Rotation: thread
Idle_Rotation = task.defer(
   function()
       while true do
           print(coroutine.status(Idle_Rotation))
           task.wait(1)
       end
   end
)

It will always print “running”, because again, we are getting the status of the task that is currently running (Idle_Rotation).

Now here’s the thing, based off your most recent comment, it’s looking like you want to yield the Idle_Rotation externally, you cannot do that.

Because again, Luau is running each task one by one. So you can only ever yield the task that is currently running, since every task that ran before it is either already yielded or dead, and every task that is scheduled to run after it is already yielded.

So I highly recommend you just rework/redesign what you have so it doesn’t rely on that type of idea.

Also just to throw this in, you don’t need “while Idle == true do” and then the following “if Idle == false then break end”, that first statement will already end the while loop if it isn’t true, so all you need is “while Idle do”.

Oh, thank you. That makes a lot more sense!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.