Over the coming weeks, we are going to be making changes to the way
coroutine.yield works. If you are using this method in your game you could be affected. Below are details on how to update your game to avoid being impacted by this change.
What is the change?
coroutine.yield will (in certain situations) cause the thread to yield for the default wait time, and then automatically be resumed. With this change, we will no longer automatically resume any threads which have yielded through the use of this method. Instead, you must explicitly resume these threads yourself.
Why are we making it?
The behavior in its current form is inconsistent depending on where the method is called.
- If it’s called from a Roblox thread, it will yield for the default wait time.
- If it is called from a user-created thread, it will yield the thread until the user explicitly resumes the thread.
We have decided to make this change in order to unify the behavior, regardless of where the method is called. This is already reflected in the developer hub.
There are also benefits which stem from this, such as the following example which allows you to wait for multiple events to complete before you continue running your code.
local function waitForEvents(events) local thread = coroutine.running() local c = 0 for i = 1, #events do local listener listener = events[i]:Connect(function () listener:Disconnect() c = c + 1 if c == #events then coroutine.resume(thread) end end) end coroutine.yield() end
What should you do?
Those of you who are affected by this change are relying on the behavior where
coroutine.yield yielding for the default wait time. If this is the case, then in a few weeks you will start seeing a warning in the output and developer console. To ensure your games continue to function as expected, please substitute these calls to
coroutine.yield with a call to
When will this happen?
You will start to see the warning if you are relying on this behavior. On the 10th of September (9/10/18), we will enable this change, and the warning will no longer be shown. If you have not updated your games before this time, they could break.