I’m running into a problem where the Network Latency doesn’t seem to consistently give correct values when calculating for the latency offset. Here’s a code example to give you a better idea:
Here is my service:
MouseEvent.OnServerEvent:Connect(function(player: Player, projectileTable: DataType.ProjectileTable)
if not player.Character then
return warn("Character does not exist on server!")
end
RenderEvent:FireAllClients(player, projectileTable, tick())
playGunSound(projectileTable)
end)
Here is the client controller:
RenderEvent.OnClientEvent:Connect(function(player: Player, projectileTable: DataTypes.ProjectileTable, arrivalTime : number)
if player == game.Players.LocalPlayer then
return
end
local latencyOffset = tick() - arrivalTime
print("Latency offset: "..latencyOffset)
Projectile.new(player, projectileTable, ProjectileCastController.bulletParent, latencyOffset)
end)
And it seems as if every time I test (Locally in Studio with 2-3 players), the network latency seems to fluctuate randomly either giving me a negative or a positive in the thousands. Very rarely it gives my desired amount, which is around 0.03-0.40. (Which seems realistic, at least on my PC).
When I attempt to test it solo in studio, it seems to work fine…but once multiple players get involved the numbers seem to change drastically.
Any ideas on what can be done here? Or is there a different method to get the network latency time?