# How to create timer in Lua Server Runtime

**URL:** <https://forum.heroiclabs.com/t/how-to-create-timer-in-lua-server-runtime/4953>\
**Category:** Runtime Framework\
**Created:** [February 6, 2024, 1:58am UTC](https://forum.heroiclabs.com/t/how-to-create-timer-in-lua-server-runtime/4953 "2024-02-06T01:58:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![whkhk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/whkhk/32/2059_2.png) [@whkhk](https://forum.heroiclabs.com/u/whkhk)\
**Post date:** [February 6, 2024, 1:58am UTC](https://forum.heroiclabs.com/t/how-to-create-timer-in-lua-server-runtime/4953/1 "2024-02-06T01:58:08Z")

</div>

I am new at Nakama and I wnat to use the server rumtime to creat the traffic light system, by putting the countdown timer and send the colour status to the game client. But I need to add the countdown finction, how to do that? It seems that I cannot use timer.performWithDelay and sleep etc?

Thanks!

---

<div class="post-metadata">

**Author:** ![mofirouz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mofirouz/32/1523_2.png) [@mofirouz](https://forum.heroiclabs.com/u/mofirouz)\
**Post date:** [February 6, 2024, 8:21am UTC](https://forum.heroiclabs.com/t/how-to-create-timer-in-lua-server-runtime/4953/2 "2024-02-06T08:21:36Z")

</div>

You shouldn’t use Timers. Instead you should use an AuthoritativeMatch that sends the traffic light colours as per GameLoop invocation to your client(s).

---

<div class="post-metadata">

**Author:** ![whkhk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/whkhk/32/2059_2.png) [@whkhk](https://forum.heroiclabs.com/u/whkhk)\
**Post date:** [March 5, 2024, 5:22am UTC](https://forum.heroiclabs.com/t/how-to-create-timer-in-lua-server-runtime/4953/3 "2024-03-05T05:22:37Z")

</div>

Thanks for your direction, but should I use tick\_rate to control the time of changing the traffic light signal? Thanks!

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [March 5, 2024, 11:42am UTC](https://forum.heroiclabs.com/t/how-to-create-timer-in-lua-server-runtime/4953/4 "2024-03-05T11:42:52Z")

</div>

@whkhk yep, you can use the current tick and `tick_rate` within a match loop to infer elapsed time.

---

<div class="post-metadata">

**Author:** ![whkhk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/whkhk/32/2059_2.png) [@whkhk](https://forum.heroiclabs.com/u/whkhk)\
**Post date:** [April 22, 2024, 6:49am UTC](https://forum.heroiclabs.com/t/how-to-create-timer-in-lua-server-runtime/4953/5 "2024-04-22T06:49:01Z")

</div>

Thanks, and can I have a more guide about that, I am very new to this… Also is there any good example code that can let me know more about? Thanks!

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [April 22, 2024, 10:24am UTC](https://forum.heroiclabs.com/t/how-to-create-timer-in-lua-server-runtime/4953/6 "2024-04-22T10:24:40Z")

</div>

Have a look at our [tic-tac-toe template](https://github.com/heroiclabs/nakama-project-template/blob/master/match_handler.ts).
