# setTimer (Shared)

> Calls a function after an interval, once or repeatedly.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Shared
- **Category**: Timers and async
- **URL**: https://wiki.mymp.gg/en/setTimer

## Syntax

```lua
timer|false setTimer(function callback, float interval, any ... [, int repeats = 1])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `callback` | `function` | The function to call. |
| `interval` | `float` | The interval in milliseconds, at least 1. |
| `repeats` | `int` | How many times to call it. `0` repeats forever. *(default: `1`)* |
| `...` | `any` | Arguments passed to the function on every call. |

## Returns

The timer, or `false` if the interval is under 1 ms.

A resource's timers stop with it. If the server or the game stalls for several intervals, the timer is called once, not once per missed interval.

## Example

```lua
local seconds = 10
setTimer(function()
    seconds = seconds - 1
    outputDebugString(seconds .. " seconds left")
end, 1000, seconds)
```

### Coming from MTA

The timer is a number, not an element, and belongs to the resource that created it: other resources cannot see it.

## See also

- [killTimer (Shared)](https://wiki.mymp.gg/en/killTimer.md): Cancels a timer before it ends.
- [setTimerPaused (Shared)](https://wiki.mymp.gg/en/setTimerPaused.md): Pauses or resumes a timer. While paused it keeps the time it had left and is not called.
- [getTimerDetails (Shared)](https://wiki.mymp.gg/en/getTimerDetails.md): Reads a timer's state: how long is left, how many repeats remain and its interval.
- [isTimer (Shared)](https://wiki.mymp.gg/en/isTimer.md): Tells whether a timer still exists in this resource.
