# yield

```lua
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
```

{% hint style="success" %}
Find details on deltaTime at this link:\
[API Reference & Tips](/lua-scripting-api/api-reference-and-tips.md#pre-data)&#x20;
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.streamavatars.com/lua-scripting-api/api-reference-and-tips/global-functions/yield.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
