Help with client/server time

Hi,

I am firing a remote event to the server with the client’s tick (playerTime = tick()). I know that the server’s timezone can be different from the client’s timezone which would affect the tick()'s. So what I did was convert the seconds to hours so I can use it to get the seconds (since seconds are the same in all timezones). Subtracting the servers seconds to the clients seconds should give me the travel time from client to server but it’s giving me some wacky numbers. Also, this works perfectly in studio but not in-game. Can someone tell me what I’m missing?

event.OnServerEvent:Connect(function(player, playerTime)
       
       local endTime = tick( )

       local clientHours = playerTime / 3600
       local clientMinutes = (clientHours % 1) * 60
       local clientSeconds = (clientMinutes % 1) * 60
    
       local serverHours = endTime / 3600
       local serverMinutes = (serverHours % 1) * 60
       local serverSeconds = (serverMinutes % 1) * 60
        
       local timeDifference = serverSeconds - clientSeconds

end)

wait im wrong, nvm. gimme a sec

i recommend using the os.time()
function like this

--client
remoteEvent.FireServer(os.time())
--server
remoteEvent.OnServerEvent:Connect(function(plr,startTime)
   print("the time difference in seconds is:"..os.time()-startTime
end)

I tried this and there was an issue with this but let me go check so I can tell you what it is

this way would allow for the time to synchronized since its based on utc and btw it is gonna print 0 seconds because remote event will fire in under second assuming low latency.

This might be a roblox issue, because now I am getting a time difference of -7/-8 (similar to what I was getting with the example I provided)

can you send the code #30characterlimit

I think I am going to report it to roblox

event.OnServerEvent:Connect(function(player, playerTime)
      local endTime = os.time()
      local timeDifference = endTime - playerTime
end)

on the client did you use os.time() too like i said to when your firing the event and can i see that code too

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		dealDamageHelper:FireServer(os.time())
	end
end)

seems strange cuz thats exactly what i did to test it , btw ensure that you are not firing the event from anywhere else on the client.

Make sure you test it in a server and not in studio, in studio your client is basically the server so it’s going to work.

oh ok ill try that now 30characters

Why don’t you use RemoteFunctions instead of RemoteEvents? You’ll get round-trip time, but you can divide by two.

--Server
local t = tick()
local client = Event:InvokeClient(Plr)
local Ping = (tick()-t)/2

--Client
Event.OnClientInvoke = function() return true end)

you cannot use tick() for what he is doing it is not the same on server and client

also i read you shouldnt use invoke client because hackers can leave the server hanging

1 Like

Your method does work, but what I am trying to do is a little time sensitive so I am trying to get the exact time it takes for the event to travel from client to server (this same event does other stuff on server I just provided you with the barebones).

Irrelevant, since it only gets called on the server.

Fair, yet you could use a separate thread and with a time limit so it won’t have impact.

thats not a viable way of solving the problem

oh and it does work in game for me just tested it