Skip to content

Api > CoroutineTools > WaitForSeconds()


CoroutineTools.WaitForSeconds(number seconds)⚓︎

When used inside a coroutine function, suspends the coroutine execution for the given amount of seconds.

Parameters:⚓︎

Name Type Description
seconds number The amounts of seconds to suspend the coroutine.

Usage⚓︎

---@type number
local seconds;


CoroutineTools:WaitForSeconds(seconds)

Example⚓︎

Notice that there is no requirement to prefix yield return or anything else to front of this function (unlike C# counterpart in the Unity.

do
    local scp = LUA.script;
    local num = 0;

    -- Wait for 5.5 second and then add 100 to num, by one on each frame
    local function coro()
        CoroutineTools.WaitForSeconds(5.5);
        for i=0,100, 1 do
            num = num + 1;
            coroutine.yield();
        end    
    end

    function scp.Start()
       scp.StartCoroutine(coro); 
    end
end