How do I do this correctly? Currently when firing a remote event I pass tick() as one of the arguments and on the server I do tick()-sentTick, but most of the time it either comes up with negative values or 0.5-1 which makes no sense as I’m doing it in a local server.
Try:
local t = tick()
Function:InvokeClient(Player)
print(tick() - t)
Should work.
https://github.com/Quenty/NevermoreEngine/blob/version2/Modules/Time/TimeSyncManager.lua#L98
This library for synchronized time between the server and the client might be useful.
You could also use the logic it uses to calculate the one way delay.
How do I actually use it? I looked on the website and the API website, but couldn’t find any straightforward tutorial on how to use the TimeSyncManager.
Require the module on both the server and the client, this will return an object that you can use for clock operations. MasterClock on the server, and SlaveClock on the client.
Fire a remote event from the server with the result from the MasterClock:GetTime().
On the client, when receiving the event make sure that the clock is synced using SlaveClock:IsSynced(), otherwise this is not valid…
The time the remote event took to arrive is SlaveClock:GetTime() - the time value you sent over the remote event.
Works great! I have one question though, how can the clocks become unsynced and what should I do if they do?
It will only be unsynced when you first create the client clock, before it is synced with the server. The client resyncs with the server every 5 seconds, so issues due to changes in network latency shouldn’t be too much of a problem.
Can anyone reupload this script? The link is down
Check the repository first before bumping a 2 year old please.
TimeSyncManager linked above is from an old branch of Nevermore which is no longer active. Nevermore updates enough to warrant tracking changes to the repository.
TimeSyncManager has been superseded by TimeSyncService.
Oh yeah sorry for that, but thanks so much for this anyway!