while true do for s,U in pairs(Players:GetPlayers())do spawn(function()if U and U.Parent==Players then if not pings[U]then pings[U]={Pings={},Average=0}end local s=tick()pcall(function()REMOTES.Ping:InvokeClient(U)end)local p=tick()-s if pings[U]then table.insert(pings[U].Pings,p)if#pings[U].Pings>5 then table.remove(pings[U].Pings,1)end local s=0 for U,p in pairs(pings[U].Pings)do s=s+p end pings[U].Average=s/#pings[U].Pings end end end)end wait(1)end
-- ping loop

while true do
	for _, player in pairs(Players:GetPlayers()) do
		spawn(function()
			if player and player.Parent == Players then
				if not pings[player] then
					pings[player] = {
						Pings = {},
						Average = 0,
					}
				end

				local start = tick()
				pcall(function()
					REMOTES.Ping:InvokeClient(player)
				end)
				local elapsed = tick() - start

				if pings[player] then
					table.insert(pings[player].Pings, elapsed)
					if #pings[player].Pings > 5 then
						table.remove(pings[player].Pings, 1)
					end

					local average = 0
					for _, ping in pairs(pings[player].Pings) do
						average = average + ping
					end
					pings[player].Average = average / #pings[player].Pings
				end
			end
		end)
	end
	wait(1)
end
