Ensure DateTime is synced between the server and client

Currently it is challenging to create server controlled timers that appear the same on all clients because there is no built in reliable way to send accurate timestamps between the server and client. An example is a 3 second countdown timer for the start of a race. I want to make sure all players can start moving at the exact same time so nobody has an unfair advantage because of lower ping.

If I pass the millisecond when the timer should end to the client, the client should accurately be able to show a countdown without me having do any manual time syncing, regardless of the clients ping. Currently the timestamp between the server and client can be hours off.

StartTimerRemoteEvent:FireAllClients({
    TimerEndTime = DateTime.now().UnixTimestampMillis + 3_000
})

Can’t you use workspace:GetServerTimeNow? That is automatically synced.

5 Likes

Although the above is correct, I can’t help but notice that there’s a part of this feature request that suggests DateTime is hours off between both machines - I’m pretty sure that desynchronisation by hours in real clock features, including os.time, is an old issue that was resolved years ago.

This is in a live server with the same code on the server and client (ReplicatedFirst):

image
image

DateTime provides tools to parse GMT time unless you use any of the local conversion methods (ToLocalTime or FormatLocalTime).

I found the time sync was off most commonly when playing on multiple devices. I would test it on my computer then join the same server on my phone and the times would be off by hours when using DateTime.now()