Its possible Sync time() from client and server?

So guys iam making my game spells with Effects on Cliente and Hitbox on server, i found some problems, like:

  1. When Player Join on game i Will need generate the effects for him too.
  2. Iam using time() to Sync server and client, but the time() from server is different from Client, so i need Sync server time and Client time.

I tried look some posts but it dont helpme, i dont know if tick() is more accurate or os.time(), but i only need Sync time() from Server and Client.

Both tick() and os.time() return the number of seconds since the unix epoch.
Small difference, tick() returns the number of seconds since the unix epoch from the local session’s computer.
os.time() returns the number of seconds in Universal standard time still using time elapsed on the local session’s machine. So this just accounts for timezones; tick() will not.

So if you’re syncing multiple machines (server and client), use os.time.

Edit: If two machines do not have synced time and date, this will not work.

2 Likes

Cause my friend made a teste, he put a time() on server to PRINT, and print like 0.4838748383, on client print Just 0, so have a difference.

I think os time is different on different clients, so this wouldn’t work.


You can get the network delay by calculating the ping of the client by using a remote function:

local T1 = tick()
RemoteFunction:InvokeServer()
local Ping = tick() - T1

On the server, do:

RemoteFunction.OnServerInvoke:Connect(function()
    return
end)

This will give you the ping of the client. When you get the ping, simply do what you want to do but account for the ping loss. For example, if the ping was 100ms(0.1 seconds), you would fast forward what you would be doing by 0.1 seconds to account for the delay.

1 Like

Yeah normally i send a time() on remote events from spells to get the Delay that had, so i calculate the Delay and make the the predicts, but as i saw time() on client and on server return different values, i dont know if i need worry about that difference between server and client time ()