> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rebind.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# rb.timer

> Run a function later or on an interval.

`rb.timer` runs a function once after a delay, or repeatedly on an interval.
A script reaches for it to delay an action or to poll something on a schedule.

This script prints a line every second and stops itself after five and a half seconds:

```luau theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
-- rebind: min_sdk=3.9.0 name=example version=1.0.0
local ticks = 0

local heartbeat = rb.timer.every(1000, function()
  ticks += 1
  print("tick " .. ticks)
end)

rb.timer.after(5500, function()
  heartbeat:stop()
  print("stopped after " .. ticks .. " ticks")
end)
```

| Signature | Effect |
| - | - |
| `rb.timer.after(ms: number, callback: () -> ()) -> TimerHandle` | runs once after `ms` |
| `rb.timer.every(ms: number, callback: () -> ()) -> TimerHandle` | runs every `ms`, measured from the previous run |
| `rb.timer.stop_all() -> ()` | stops every timer of the script |

Timers run on the engine tick, so a timer fires at most once per tick. An error
in a callback does not stop the script; it is logged to the script's **Logs**.
The [TimerHandle](https://docs.rebind.gg/reference/sdk/handles.md) stops, pauses and resumes one timer
with `stop()`, `pause()` and `resume()`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.