Client to Server Invoke Delay

In the Studio, the invoke delay is usually ~ 0.016, using RemoteFunctions.

image

However, in the Player, it’s ~ -3599 for some reason.

image

When invoking the server from the client, I pass in the parameters tick() to eliminate the time it takes for the invoke to reach the server. I then use this formula:

delay = tick() - client tick

to calculate the delay between both tick()s.

Why is this happening and how can this be prevented? The expected results only appear in the Studio.

Steps to reproduce:

RemoteFunction in ReplicatedStorage.

-- client
RemoteFunction:InvokeServer(tick())
-- server
RemoteFunction.OnServerInvoke = function(_, clientTick)
    print(tick() - clientTick)
end
--SERVER

local Game = game
local ReplicatedStorage = Game.ReplicatedStorage
local RemoteFunction = ReplicatedStorage.RemoteFunction

local function OnInvoked()
	return
end

RemoteFunction.OnServerInvoke = OnInvoked
--CLIENT

local Game = game
local ReplicatedStorage = Game:GetService("ReplicatedStorage")
local RemoteFunction = ReplicatedStorage:WaitForChild("RemoteFunction")

task.wait(5)
local Clock = os.clock()
RemoteFunction:InvokeServer()
print(os.clock() - Clock) --0.03228729998227209

I’m getting ~0.03 seconds, you’re likely invoking the server before everything has had a chance to initialize.

1 Like

The server can be in a totally different continent than you, so it’s tick can be hugely different from the client’s, as it’s based on local timezone. You should be using workspace:GetServerTimeNow() on the client.

1 Like