Using GetNetworkPing in Studio

Hey, and thanks for reading in advance.

I’m attempting to create a function that validates a list of targets sent by a client-created hitbox, using the player’s ping to determine their approximate location based on movement.

Problem being, Player:GetNetworkPing() seemingly always returns 0 in Studio testing. That obviously can’t be accurate, as the server’s idea of my character’s position is off by almost an entire second:

The purple box is actually two overlayed hitboxes, one red, one blue (client/server). The yellow markers indicate the server’s estimated position based on my ping, but since the game thinks my ping is zero, it isn’t extrapolating towards the correct position at all.

Code:

function HandleRegion(Player, ActionName, Targets, CF, Size)
	if Player.Character and Core:GetStat(Player.Character, "Health") > 0
	and Player.Character:FindFirstChild("HumanoidRootPart") then
		local Class = Core:GetStat(Player.Character, "Class", "Villager")
		local Upgraded = Core:GetStat(Player.Character, "Upgrade", false)
		local Root = Player.Character.HumanoidRootPart
		
		if ActionName == "Primary" then
			local AbilityFunction = (Upgraded and Abilities[Class].UpgradePrimary)
				or Abilities[Class].Primary
			
			local HitReg = Player_HitRegistry[Player]
			local GuessPosition = Root.Position + (Root.AssemblyLinearVelocity * Player:GetNetworkPing())
			
			--
			local GuessMark = Instance.new("Part")
			GuessMark.Size = Vector3.new(1, 1, 1)
			GuessMark.Position = GuessPosition
			GuessMark.Anchored = true; GuessMark.CanCollide = false
			GuessMark.Material = Enum.Material.Neon
			GuessMark.Color = Color3.new(1, 1, 0)
			GuessMark.Parent = workspace
			
			game.Debris:AddItem(GuessMark, 5)
			--

			if AbilityFunction and HitReg then
				if Size == AbilityFunction.REGION_SIZE then -- idiot trap
					if (GuessPosition - CF.Position).Magnitude <= 10
						+ (GuessPosition - Root.Position).Magnitude
						+ AbilityFunction.REGION_OFFSET then
						
						local LagFactor = math.clamp(Player:GetNetworkPing() / 90, 1, 1.2)
						local ServerTargets = Core:Hitbox(CF, Size * LagFactor)
						
						local CuratedTargets = {}
						
						for _,Entity in pairs(Targets) do
							if not table.find(HitReg, Entity) and table.find(ServerTargets, Entity) then
								table.insert(CuratedTargets, Entity)
								table.insert(HitReg, Entity)
							end
						end
						
						AbilityFunction.Server(Player.Character, CuratedTargets)
					else
						warn("Hitbox Security Warning: Suspect Hitbox Placement")
					end
				else
					warn("Hitbox Security Warning: Size Mismatch")
				end
			end
		end
	end
end

Any help or advice is appreciated.

2 Likes

Did you find a way to simulate the ping in editor?
I am using StudioSettings/Network/IncomingReplicationLag value to test but i still get 0 ping in studio

I am also getting this using IncomingReplicationLag and it returns 0. This function seems completely useless if I can’t properly test the ping in studio.