Getting elapsed time irrespective of time zones

What I’m trying to do is ensure that the client and server are perfectly synchronized. To do this, I make the client send the time it started some event, then the server receives the message and deduces how much time has passed between the start and reception, so it knows how much progress it made.

I can’t send to the server “progress: 38/120” for example, because the client-server delay ensures that by the time it reaches, there will have been more progress made.

I’ve used os.time(), but the issue is it returns wildly different values based on time zones.

I’ve considered comparing os.time() on server and client, then adjusting what the client believes os.time() is based on the result. But for the precision I need, this won’t do. If the server says “os.time() is 3 hours behind,” the client will account for that but by the time it reaches the client, the client’s os.time() will be inflated because of the delay, causing os time to be around 100 ms (or more depending on ping) greater than what it should be.

time() is useless. same with workspace.DistributedGameTime. They start at 0 when the client joints the game, and sending the server’s value to the client is useless for the aforementioned reason.

Simply put, I need a time function that returns the same on all clients, and the server as well.

Are you sure of this? os.time is supposed to be standardized as UTC. tick() is the one that varies by time zone.

I see. I’m basing this off of some prior issues I had with os.time(), but you may be right.

The issue with this is that os.time() only displays seconds. I’m making fast-paced combat with this so I need more precision.

1 Like