Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

os.time or tick()?

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

✓ Accepted answer

os.time()

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:

print(os.difftime(tick(),os.time())/3600)

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:

http://unattended.sourceforge.net/timezones.php

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

1 comment

0

Thanks! This was very helpful

This discussion is preserved as it was. New answers, comments, and votes are closed.