I am wondering how to use coroutine.yield() because i can't figure out how it works. I have tried to understand the article on the Roblox's own devhub, but I just can't understand it. Can anyone help?
Code:
function Alarms.On(Color) for i, v in pairs(Alarms.AlarmTable) do v.Activate(Color) -- Activates a bunch of smaller scripts coroutine.yield() -- Tries to yield but fails end end
Basically coroutine.yield() will pause the script so nothing continues until what is inside of the () is completed. You appear to be using it wrong in your script, an example of how I would use it is below.
local num = 0; while true do wait(); print("Adios: " .. num); coroutine.yield(num += 1); -- This acts as a wait() but instead of passing a number it waits until whatever I put inside it is completed. Once complete it will continue the script. end
(If you have previously coded in C#, JS, etc. You will find that you can use await inside of async functions coroutine.yield() is like an await but can be used anywhere and is a lua version of await.)