local function H()charactersTotalVolume=0 bodyParts={}local H={UpperTorso=true;LowerTorso=true;Torso=true;LeftHand=true;RightHand=true,LeftFoot=true;RightFoot=true}for G,n in pairs(players:GetPlayers())do local Q=ZoneController.getCharacterRegion(n)if Q then local G=Q.Size local O=(G.X*G.Y)*G.Z charactersTotalVolume+=O for G,n in pairs(n.Character:GetChildren())do if n:IsA("\066\097\115\101\080\097\114\116")and not H[n.Name]then table.insert(bodyParts,n)end end end end end players.PlayerAdded:Connect(function(G)G.CharacterAdded:Connect(function(G)local n=G:WaitForChild("\072\117\109\097\110\111\105\100",3)if n then H()for G,n in pairs(n:GetChildren())do if n:IsA("\078\117\109\098\101\114\086\097\108\117\101")then n.Changed:Connect(function()H()end)end end end end)end)players.PlayerRemoving:Connect(function(G)H()playerExitDetections[G]=nil end)
-- CHARACTER HANDLER
-- This enables character data (volume, HumanoidRootParts, etc) to be handled on
-- an event-basis, instead of being retrieved every interval
local function updateCharactersTotalVolume()
	charactersTotalVolume = 0
	bodyParts = {}
	-- We ignore these due to their insignificance (e.g. we ignore the lower and
	-- upper torso because the HumanoidRootPart also covers these areas)
	-- This ultimately reduces the burden on the player region checks
	local bodyPartsToIgnore = {
		UpperTorso = true,
		LowerTorso = true,
		Torso = true,
		LeftHand = true,
		RightHand = true,
		LeftFoot = true,
		RightFoot = true,
	}
	for _, plr in pairs(players:GetPlayers()) do
		local charRegion = ZoneController.getCharacterRegion(plr)
		if charRegion then
			local rSize = charRegion.Size
			local charVolume = rSize.X * rSize.Y * rSize.Z
			charactersTotalVolume += charVolume
			for _, part in pairs(plr.Character:GetChildren()) do
				if part:IsA("BasePart") and not bodyPartsToIgnore[part.Name] then
					table.insert(bodyParts, part)
				end
			end
		end
	end
end
players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local humanoid = char:WaitForChild("Humanoid", 3)
		if humanoid then
			updateCharactersTotalVolume()
			for _, valueInstance in pairs(humanoid:GetChildren()) do
				if valueInstance:IsA("NumberValue") then
					valueInstance.Changed:Connect(function()
						updateCharactersTotalVolume()
					end)
				end
			end
		end
	end)
end)
players.PlayerRemoving:Connect(function(plr)
	updateCharactersTotalVolume()
	playerExitDetections[plr] = nil
end)
