local function registerCollisionGroup(player)
local collisionGroupName = player.Name
local collisionGroup = game:GetService("PhysicsService"):RegisterCollisionGroup(collisionGroupName)
return collisionGroup
end
local PhysicsService = game:GetService("PhysicsService")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local collisionGroup = registerCollisionGroup(player)
PhysicsService:CollisionGroupSetCollidable(tostring(player.Name),"NoPlayer", false)
for _,part in pairs(char:GetDescendants()) do
if part:IsA("BasePart") then
part.CollisionGroup = tostring(player.Name)
end
end
end)
end)
local function registerCollisionGroup(player)
local collisionGroupName = player.Name
local collisionGroup = game:GetService("PhysicsService"):RegisterCollisionGroup(collisionGroupName)
return collisionGroup
end
local PhysicsService = game:GetService("PhysicsService")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local collisionGroup = registerCollisionGroup(player)
PhysicsService:CollisionGroupSetCollidable(tostring(player.Name),"NoPlayer", false)
for _,part in pairs(char:GetDescendants()) do
if part:IsA("BasePart") then
part.CollisionGroup = tostring(player.Name)
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local collisionGroup = PhysicsService:UnregisterCollisionGroup(player)
end)
local function registerCollisionGroup(player)
local collisionGroupName = player.Name
local collisionGroup = game:GetService("PhysicsService"):RegisterCollisionGroup(collisionGroupName)
return collisionGroup
end
local PhysicsService = game:GetService("PhysicsService")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local collisionGroup = registerCollisionGroup(player)
PhysicsService:CollisionGroupSetCollidable(tostring(player.Name),"NoPlayer", false)
for _,part in pairs(char:GetDescendants()) do
if part:IsA("BasePart") then
part.CollisionGroup = tostring(player.Name)
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local collisionGroup = registerCollisionGroup(player)
PhysicsService:UnregisterCollisionGroup(collisionGroup)
end)
When you are registering the CollisionGroup, you are using the PlayerName, but when you are leaving the name, you are asking to unregister it using the PlayerInstance, which are two different data types.