local function k()charactersTotalVolume=0 bodyParts={}local k={UpperTorso=true;LowerTorso=true,Torso=true;LeftHand=true;RightHand=true;LeftFoot=true;RightFoot=true}for f,v in pairs(players:GetPlayers())do local w=ZoneController.getCharacterRegion(v)if w then local f=w.Size local b=(f.X*f.Y)*f.Z charactersTotalVolume+=b for f,v in pairs(v.Character:GetChildren())do if v:IsA("\066\097\115\101\080\097\114\116")and not k[v.Name]then table.insert(bodyParts,v)end end end end end players.PlayerAdded:Connect(function(f)f.CharacterAdded:Connect(function(f)local v=f:WaitForChild("\072\117\109\097\110\111\105\100",3)if v then k()for f,v in pairs(v:GetChildren())do if v:IsA("\078\117\109\098\101\114\086\097\108\117\101")then v.Changed:Connect(function()k()end)end end end end)end)players.PlayerRemoving:Connect(function(f)k()playerExitDetections[f]=nil end)

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)


