How would I delete a collision group after the player has left?

script:

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)



how would i detect if th eplayer left or not

PlayerRemoving:

i tried, it wasnt working

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)

Do you mean:

darn, i thought that was the problem, but no

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)

ok, so basically,

When you are registering the CollisionGroup, you are using the Player Name, but when you are leaving the name, you are asking to unregister it using the Player Instance, which are two different data types.

oh bruh, i am stupid. i thought the function was a native function of physic service lol, thanks a lot

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.