Scripting Helpers is winding down operations and is now read-only. More info→
Log in to vote

os.time or tick()?

Asked by 8 years ago

So I'm making an upgrade system that continues the upgrade timer even when the player isn't online. (Example, think of Clash of Clans. When you start an upgrade, you can get offline and the upgrade timer will continue to countdown).

However, I'm new to both os.time and tick(). I've read many wikis and posts on both of them, but I can't figure out which one to use for this type of script.

Which one should I use?

1 answer

Log in to vote
Answered by 8 years ago


os.time() always returns Unix time. If you are unsure what Unix time is, Unix time is defined as the number of seconds that have passed since 00:00:00 Coordinated Universal Time, Thursday, 1 January 1970.

Since tick() always returns what the users local time is, it is an inefficient way to keep track of time over multiple servers. The best thing to do is use os.time() which chooses one timezone [Unix (which is equivalent to GMT)] and records that. This way you can keep the standard of keeping time universal for all players.

If you want to see a neat trick to figure out a timezone, take the difference between the local users time, and os.time() and compare with a list:


For me, since I am in Eastern Timezone which is also GMT -04:00, the result that got printed was -4. Using this, you can try and guess what timezone the player is in with a list such as:

Therefore, in summary, you should use os.time() to keep a standard principle of time.

Thanks! This was very helpful ZeMeNbUiLdEr 104 — 8y

Answer this question