local N={}local function u(u)if u:IsA("\066\097\115\101\080\097\114\116")or u:IsA("\085\110\105\111\110\079\112\101\114\097\116\105\111\110")then N[u]=u.CollisionGroup u.CollisionGroup=playerCollisionGroupName end end local function v(N)u(N)for N,u in ipairs(N:GetChildren())do v(u)end end local function L(u)local v=N[u]if not v then return end u.CollisionGroup=v N[u]=nil end local function b(N)v(N)N.DescendantAdded:Connect(u)N.DescendantRemoving:Connect(L)end local function o(N)N.CharacterAdded:Connect(b)end Players.PlayerAdded:Connect(o)


local previousCollisionGroups = {}

local function setCollisionGroup(object)
	if object:IsA("BasePart") or object:IsA("UnionOperation") then
		previousCollisionGroups[object] = object.CollisionGroup


		object.CollisionGroup = playerCollisionGroupName
		--PhysicsService:SetPartCollisionGroup(object, playerCollisionGroupName)
	end
end

local function setCollisionGroupRecursive(object)
	setCollisionGroup(object)

	for _, child in ipairs(object:GetChildren()) do
		setCollisionGroupRecursive(child)
	end
end

local function resetCollisionGroup(object)
	local previousCollisionGroup = previousCollisionGroups[object]
	if not previousCollisionGroup then return end 

	--local previousCollisionGroupName = PhysicsService:GetCollisionGroupName(previousCollisionGroupId)
	--if not previousCollisionGroupName then return end

	object.CollisionGroup = previousCollisionGroup
	--PhysicsService:SetPartCollisionGroup(object, previousCollisionGroupName)
	previousCollisionGroups[object] = nil
end

local function onCharacterAdded(character)
	setCollisionGroupRecursive(character)

	character.DescendantAdded:Connect(setCollisionGroup)
	character.DescendantRemoving:Connect(resetCollisionGroup)
end

local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end

Players.PlayerAdded:Connect(onPlayerAdded)
