-- 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
