Which one should I use? time

So, that will be the same for client and server?

It’ll not be equal, since it’s based on the machine’s time (not timezone). It’ll return the UTC time, but that time will still not be synchronized to the server’s UTC time. Nothing is stopping the player to change their time to the past or future. You can only trust that the server’s time is correct.

You could do something like add the server’s time to a NumberValue, so it’s visible to all clients.

2 Likes

os.time() is not more accurate than tick() or time().
It is rounded to the nearest second while the others are not. That could indicate that it might indeed be faster but I don’t know.

There’s also os.clock() which has about 1 microsecond of precision and is intended for benchmarking.

1 Like

Yea, I thought I got some of them confused. They all have similar names so it is kinda hard to differentiate.

What’s wrong with time? (Not os.time.) It counts from when the server starts.

4 Likes

@rogchamp
It does not count from when the server starts. It starts counting from when the local game instance starts.

That’s what a server is. A local game instance.

2 Likes

If you test time() in Roblox Studio by starting a local server and then joining later as a player you will see that time() returns different values on the server and the client.

Do not use the ‘Play’ button because that will start the server and the client at the same time.
Use the ‘Start’ button to launch a server and then add a single player later.

DateTime is the one that independent from both time zone and client computer’s time. We should always consider DateTime first whenever we need to use time stuffs. :slightly_smiling_face:

DateTime didn’t exist at the time I made my replies. Check the date next time!

2 Likes