:OnAllClients Network Latency Offset Problem?

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?

You can accurately calculate network latency and by using workspace:GetServerTimeNow() and os.time(), which will guarantee you’ll always get a positive, monotonic number that’s extremely precise.

local NetworkTime: number = workspace:GetServerTimeNow() - os.time()

Why am I getting such drastic numbers? This was tested with only one player (me), the latency offset should be around 0.03 - 0.10 and should not be as high as 1.003
image

Here is my code:

RenderEvent.OnClientEvent:Connect(function(player: Player, projectileTable: DataTypes.ProjectileTable, arrivalTime : number)
		local latencyOffset = workspace:GetServerTimeNow() - arrivalTime
		
		print("Latency offset: "..latencyOffset)

		Projectile.new(player, projectileTable, ProjectileCastController.bulletParent, latencyOffset)
	end)