setTimer | Multi Theft Auto: Wiki Skip to content

setTimer

Client-side
Server-side
Shared

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


This function allows you to trigger a function after a number of milliseconds have elapsed. You can call one of your own functions or a built-in function. For example, you could set a timer to spawn a player after a number of seconds have elapsed.

Note

The hidden global variable sourceTimer contains the currently executing timer userdata

Note

The hidden global variable source becomes nil inside a timer function. You need to declare it on the function arguments if you need to use it.

Important

The speed at which a client side timer runs can be completely unreliable if a client is maliciously modifying their operating system speed, timers could run much faster or slower.

Important

Writing the following code can cause performance issues. Use onClientPreRender instead. setTimer(theFunction, 0, 0)

Syntax

setTimer ( )

Code Examples

server

This example will output some text after a small delay.

-- define function to be called
function delayedChat ( text )
outputChatBox ( "Delayed text: " .. text )
end
-- set a timer so the function is called after 1 second
setTimer ( delayedChat, 1000, 1, "Hello, World!" )