Which one should I use? time

I use tick() but I heard is deprecated :frowning: .

I just printed tick, os.clock and os.time… (This results are from Yesterday)

tick -> 1597077449.0203
clock -> 1621306.7259923
time -> 1597091849

Which one should I use? I was using tick() for rewards.

EDIT: I need something that is the same for server and client, cuz tick I heard is different from time zones.

7 Likes

tick() returns how many seconds have passed since the EPOCH time (January 1st 1970) in the machine’s timezone.
os.clock() returns the amount of CPU time used by Lua in seconds.
os.time()returns how many seconds have passed since the EPOCH time, however it is more precise and you can control the format, and which timezone it’s based on.

tick() works fine in most cases, but os.time() is more precise so it should be used instead.

24 Likes

Which one is the same for client and server?

1 Like

If you’re looking to make rewards, do

tick() - tick()

This way, you have a reliable time-frame in which you can make it so that people can collect daily rewards.

Edit: Idk but someone might be able to manipulate tick() but im not sure. :neutral_face:

4 Likes

The time will be nearly the same in both tick() and os.time(), since they use UTC. However, you cannot expect it to be equal since it’s based on the local machine’s time. workspace.DistributedTime won’t work either, since it’s currently not synced between the server and clients.

4 Likes

For server logic that is dependent on time (such as daily rewards) you should be using os.time() on the server because it is synced across Roblox servers to use the same timezone.
You should not be using tick() from the server or os.time() from the client.

If you want something that that is synced between the server and the client you will have to write some code to sync the server os.time() to the client.

6 Likes

Oh ok, because as I heard, all servers are in the US so that means if someone that is in Australia plays, their tick() is going to be different. Maybe that’s why my reward was glitching for the client…

3 Likes

tick() is based on UTC time, so it should be equal independently from the location.

3 Likes

Is there at least just a number that keeps increasing but that is not part of the time?

1 Like

Yeah tick() is based on the timezone that the client or server is in. The way you should set up your rewards system is to periodically check os.time() from the server and then tell the client if they are eligible to collect a reward. And then you check it again when they send a message back saying that they want to collect their reward. You should not be verifying it on the client.

3 Likes

workspace.DistributedTime begins when the server starts running/client enters the game, maybe you’re looking for that?

3 Likes

What I used to do is check if they have a reward, if so they fire a remote event, then the server rechecks. In case of an exploiter.

1 Like

I mean, I think DistributedGameTime restarts once is a new server.

1 Like

tick() is dependent on the time zone that the computer is set to.

4 Likes

My bad, I read a document wrong. tick() is indeed based on local time.

4 Likes

I would like Roblox to add a value that just keeps increasing but that is not time…

1 Like

Can you please explain in detail what are you trying to achieve?

2 Likes

I know I can do this via a remote function, but still. I would like to have a number that keeps increasing, something like tick(), but that it doesn’t work depending on the time zone.

os.time() does exactly that. It returns the UTC time by default.

2 Likes

tick is not deprecated afaik, though it is superseded by time.
os.time() is faster and more accurate, so it’s better to use that I’m pretty sure.

3 Likes