Tick() that is the same on both the client and the server?

Basically whenever you use function tick() on the client and the server individually and if you wanted to compare those values, the time difference will be thousands of seconds off. You might try to guide me back to previous posts using Quenty’s TimeSyncManager or TimeSyncService. However, I have used both of these modules, and I have used the proper functions on both the server and client using these modules to absolutely make sure they were “synced” before I used them. However, even if I used the traditional tick() or whether I used Quenty’s modules, the tick was still thousands of seconds off.

Basically, I’m making a game where you would want to complete a level in the fastest possible time. As you are playing the level, I want the timer to accurately show the time you are at now. The problem with having it all server sided is that if your ping is high, the timer will lag with it. But on Roblox I have found no accurate method that returns a synced time. The synced time I’m looking for has to be in milleseconds, so os.time() is too vague as it only counts in integer seconds.

If anyone could help me with this, it is so greatly appreciated! :smiley:

Yeah… That shouldn’t be happening.

If you implemented Quenty’s TimeSyncService correctly, you should be getting “ticks” that are within ±1/30 seconds of each other.

I would suggest taking another look at your implementation and see if there is a mistake you made somewhere.

Personally, I’ve used Quenty’s TimeSyncManager for syncing projectiles on the server and client and it worked perfectly.

tick() depends on the local timezone of each machine. That’s why there is a big difference. Did you try using os.clock()? I don’t know if that’s based on UTC or local, but it’s worth a try.
Alternatively you can use os.date() with the UTC specifier or os.time() for seconds and use tick() to complement the miliseconds.

I know for sure I have implemented TimeSyncManager correctly, but I’m was not sure on how to get TimeSyncService to “work” all the way. It seems if you just copy and paste the his module on the GitHub it has a lot of other modules and remote events missing. I was able to compensate it with my own on with TimeSyncManager but I couldn’t the same for TimeSyncService. Could you tell me how you managed to make the module work and how you implemented? If you can, that will be awesome!

I just tried os.clock(), it seems just like tick() as it will be different depending on if you’re using it on the server versus the client.

I just found that Quenty made a post explaining the script himself:

I’ll follow his steps and wish for the best. Thank you guys for your time!

as mentioned, you should use quenty’s timesyncing script, but if you would go the long route just make a server sends their tick() value and the client send’s back theirs, of course tick() is based on epoch, and the system clock, meaning it isnt quite reliable at all, i would use quenty’s timesyncing script for the time being, but if latency is an issue, or your making a sort of hit registry, i would use logical predictions and raycasting in order to do so, latency can play a huge issue in time syncing. as packets take usually ~20 ms to send to the server and it bounces back to the client with the response, this may be a networking issue or answer but i mean; im not too good at networking packets on a day to day basis, so.

you can also use DateTime.now().UnixTimestampMillis / 1000, its the same for client and server
you can really easily replace tick() by adding this to the beginning of a script:

local function tick()
    return DateTime.now().UnixTimestampMillis / 1000
end

this is only accurate to 1 millisecond however

6 Likes