local function f(f)if f:IsA("\066\097\115\101\080\097\114\116")then previousCollisionGroups[f]=f.CollisionGroupId PhysicsService:SetPartCollisionGroup(f,playerCollisionGroupName)end end local function N(N)f(N)for N,o in ipairs(N:GetDescendants())do f(o)end end local function o(f)local N=previousCollisionGroups[f]if not N then return end local o=PhysicsService:GetCollisionGroupName(N)if not o then return end PhysicsService:SetPartCollisionGroup(f,o)previousCollisionGroups[f]=nil end local function r(r)N(r)r.DescendantAdded:Connect(f)r.DescendantRemoving:Connect(o)end local function y(f)f.CharacterAdded:Connect(r)end

local function setCollisionGroupForPart(part)
	if part:IsA("BasePart") then
		previousCollisionGroups[part] = part.CollisionGroupId
		PhysicsService:SetPartCollisionGroup(part, playerCollisionGroupName)
	end
end
 
local function setCollisionGroupForObject(object)
	setCollisionGroupForPart(object)
	for _, object in ipairs(object:GetDescendants()) do
		setCollisionGroupForPart(object)
	end
end
 
local function resetCollisionGroup(object)
	local previousCollisionGroupId = previousCollisionGroups[object]
	if not previousCollisionGroupId then return end 
 
	local previousCollisionGroupName = PhysicsService:GetCollisionGroupName(previousCollisionGroupId)
	if not previousCollisionGroupName then return end
 
	PhysicsService:SetPartCollisionGroup(object, previousCollisionGroupName)
	previousCollisionGroups[object] = nil
end
 
local function onCharacterAdded(character)
	setCollisionGroupForObject(character)
 
	character.DescendantAdded:Connect(setCollisionGroupForPart)
	character.DescendantRemoving:Connect(resetCollisionGroup)
end
 
local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end

