yield

API - pauses the script for x amount of seconds.

return function
    local timeCounter = 0;
    local x = 0;
    local speed = 5;
    
    wait(3.5); --pauses script 3.5 seconds before continuing...
    
    while timeCounter < 5 do --after 5 seconds this while loop will end
    
        local delta = yield();  --useful for doing work over a period of time
        
        --yield returns the time it took from last frame to this frame in seconds.
        --yield also pauses the script each frame so the while loop doesn't lock the application up
        --while doing work.
        
        timeCounter = timeCounter + delta;
        
        --you can also use the deltaTime to advance the position of something
        x = x + speed * delta; --at a rate of 5units per second, x moves right.
    end
end

Last updated