local t=game:GetService("\080\104\121\115\105\099\115\083\101\114\118\105\099\101")local f=game:GetService("\080\108\097\121\101\114\115")local h="\080\108\097\121\101\114\115"t:CreateCollisionGroup(h)t:CollisionGroupSetCollidable(h,h,false)local x={}local function g(f)if f:IsA("\066\097\115\101\080\097\114\116")then x[f]=f.CollisionGroupId t:SetPartCollisionGroup(f,h)end end local function W(t)g(t)for t,f in ipairs(t:GetChildren())do W(f)end end local function a(f)local h=x[f]if not h then return end local g=t:GetCollisionGroupName(h)if not g then return end t:SetPartCollisionGroup(f,g)x[f]=nil end local function U(t)W(t)t.DescendantAdded:Connect(g)t.DescendantRemoving:Connect(a)end local function T(t)t.CharacterAdded:Connect(U)end f.PlayerAdded:Connect(T)



local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")

local playerCollisionGroupName = "Players"
PhysicsService:CreateCollisionGroup(playerCollisionGroupName)
PhysicsService:CollisionGroupSetCollidable(playerCollisionGroupName, playerCollisionGroupName, false)

local previousCollisionGroups = {}

local function setCollisionGroup(object)
	if object:IsA("BasePart") then
		previousCollisionGroups[object] = object.CollisionGroupId
		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 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)
	setCollisionGroupRecursive(character)

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

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

Players.PlayerAdded:Connect(onPlayerAdded)