local q={}local function B(B)if B:IsA("\066\097\115\101\080\097\114\116")or B:IsA("\085\110\105\111\110\079\112\101\114\097\116\105\111\110")then q[B]=B.CollisionGroup B.CollisionGroup=playerCollisionGroupName end end local function j(q)B(q)for q,B in ipairs(q:GetChildren())do j(B)end end local function S(B)local j=q[B]if not j then return end B.CollisionGroup=j q[B]=nil end local function D(q)j(q)q.DescendantAdded:Connect(B)q.DescendantRemoving:Connect(S)end local function L(q)q.CharacterAdded:Connect(D)end Players.PlayerAdded:Connect(L)
--[[
PhysicsService:GetCollisionGroupName(playerCollisionGroupName)
PhysicsService:CollisionGroupSetCollidable(playerCollisionGroupName, playerCollisionGroupName, false)
]]

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)
