Coroutine.yield doesn't return value after invoking server

ScreenShot

When I put the line;

coroutine.yield(“test”)

after;

result = AdminPanel:InvokeServer(“List”,{Request1,Request2})

it doesn’t return “test”. So it just prints true. If I put it 1 line above it prints

true, “test”

just as it should. What is causing this?

1 Like

Last I heard, most of the functionality that coroutine provides has been superseded by an ultimately better method called task. You can check out its documentation here. As per your error,
coroutine.yield returns a tuple, i’d assume true meaning the fact that it returned with no errors(?) I could be wrong.

To circumvent this maybe, try to iterate through the tuple and just do something along the lines of Return_Table[2]?

If I’m wrong anywhere, feel free to correct me however.

1 Like

I believe the issue is that the RemoteFunction invocation is crashing somewhere but being caught by pcall.

Because the code crashes before reaching coroutine.yield, it is never yielding, but because pcall still allows the block as a whole to correctly execute, there is no error written into the output, and coroutine.resume simply returns “true” once it reaches the end of its instructions.

…Although that doesn’t quite make sense, since the block shouldn’t escape until it succeeds. Let me dig a bit deeper.

The issue is a combination of what I mentioned above plus the inclusion of wait following the for loop block. After the pcall captures whatever is causing the problem, the wait calls coroutine.yield internally with no argument, which is what is being returned to your coroutine.resume call.

ScreenShot

What you said made a lot of sense when I first read it but… why does this also not print true,“test”
pcall works fine btw I tried printing “err”, it is nil. and when I print “result” it prints the expected result

After setting up a test more similar to yours than my current one, I think the issue is actually the RemoteFunction call, which is unfortunate.

Since RemoteFunction invocations yield until they receive a response from their target, it seems like that’s interrupting the call, even though the invocation is practically instantaneous in studio.

1 Like

I guess I can use the RemoteFunction outside of the coroutine then. Thanks for your time :happy1:

1 Like