Question for networking experts on :GetNetworkPing [Solved]

I have been experimenting with this function and in its description it says “It doesn’t involve data deserialization or processing.” I experimented in game by increasing my ping on the performance stats by running a speedtest on my browser. I noticed that the increase of ping from the speedtest does not increase the ping time given by :GetNetworkPing.

With this discovery, I would like to know if this is a valid method of getting the time that it takes for a remote event to go from client to server. In other words, is the data deserialization or processing included in the time it takes for the event to move from client to server?

When you were doing the ping test, was it in studio or in game?

In the actual game, using the F9 menu to see the print statements

1 Like

This is without speedtest running:

This is with it running(I have managed to get the ping much higher before with the same result)

1 Like

It’s probably because :GetNetworkPing measures the network layers ping directly and is isolated from other activities on your device that might introduce latency. If you want to redo the experiment, try using a remoteEvent with a timestamp.

client code:

local startTime = workspace:GetServerTimeNow()
RemoteEvent:FireServer(startTime)

server code:

RemoteEvent.OnServerEvent:Connect(function(player, startTime)
    local endTime = workspace:GetServerTimeNow()
    local totalLatency = endTime - startTime
    print("Total Latency: " .. totalLatency .. " seconds")
end)
1 Like

Great idea, I will do that instead, don’t know why I did not think of it before!

1 Like

Just did the stress test with a timestamp and there was a lot of fluctuation during the test. So I suppose the answer is never to use :GetNetworkPing() for your time calculations.

1 Like

I ran the test too, and there’s a lot more fluctuations than GetNetworkPing because now we have to account for data serialization/deserialization and the application process which can change depending on a ton of different things. GetNetworkPing and remote event/function timestamps have two very different use cases
image

Also I updated the code I sent above because I realized ping was round trip and not 1 way:

client code:

local startTime = workspace:GetServerTimeNow()
RemoteFunction:InvokeServer()
print(workspace:GetServerTimeNow() - startTime)

server code:

RemoteFunction.OnServerInvoke = function(player)
	return true
end

Both methods are useful depending on what your use case is

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.