Turn CanCollide to false on Player Accessory not work

Hello everyone, since I currently have the problem that you can’t fit through the doors due to the players’ accessories, I wanted to turn off the collision, but unfortunately that doesn’t work (without an error code)

And I’m unsure if a collision group is necessary because the players are still allowed to collide each other, but without the accessory.

-- CanCollide Accessory
	for _,b in pairs(character:GetDescendants()) do
		if b:IsA("MeshPart") then
			if b.Name == "Handle" then
				b.CanCollide = false
			end
		end
	end
1 Like

Accessories should be by default, un-can-collideable. You should change the check from “MeshPart” to “BasePart” though.

Normally yes, but unfortunately not for me. And BasePart doesn’t work either.

1 Like

Show your full code. You may be setting the .CollisionGroup before every part in the character is loaded.

the entire script are over 200 lines long. but i can send a bit of the script with the part of characteradded

-- CharacterAdded (on every respawn or kill, this run everytime)
		player.CharacterAdded:Connect(function(character)
			if character then
				local character = player.Character or player.CharacterAdded:Wait()
				local humanoid = character:WaitForChild("Humanoid")
				humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
				if not character:IsDescendantOf(workspace) then
					character.AncestryChanged:Wait()
				end
				
				-- Attachment for Shooting Tower
				wantedShoot = Instance.new("Attachment")
				wantedShoot.Name = "wantedShoot"
				wantedShoot.Parent = character:WaitForChild("HumanoidRootPart")
				
				-- CanCollide Accessory
				for _,b in pairs(character:GetDescendants()) do
					if b:IsA("BasePart") then
						if b.Name == "Handle" then
							b.CanCollide = false
						end
					end
				end
				
				-- Enable Backpack
				event3:FireClient(player,true)
				
				-- Send Event to Reset Player Data Local
				event2:FireClient(player)

				-- Set Avatar to Blocky R15
				local CurrentDescription = humanoid:GetAppliedDescription()

				CurrentDescription.Torso = 0
				CurrentDescription.LeftArm = 0
				CurrentDescription.RightArm = 0
				CurrentDescription.LeftLeg = 0
				CurrentDescription.RightLeg = 0
				humanoid:ApplyDescription(CurrentDescription)
				
				-- Enable Chat
				local PlayerGui = player.PlayerGui
				local DiedGui = PlayerGui:WaitForChild("chatGUI")
				DiedGui.Enabled = true
				
				-- Car Seat
				humanoid.Seated:Connect(function(active,seat)
					if seat == nil then
						if exitAttachment == nil then return end
						for _,v in pairs(character:GetDescendants()) do
							if v:IsA("MeshPart") or v:IsA("Part") or v:IsA("UnionOperation") then
								if v.Name ~= "HumanoidRootPart" then
									v.Transparency = 0
								end
							end
							if v.Name == "nametagGUI" then
								v.Enabled = true
							end
						end
						character.PrimaryPart.CFrame = exitAttachment.WorldCFrame
						exitAttachment = nil
						return
					end
					if seat.Name == "DriveSeat" then
						seat:SetNetworkOwner(player)
						exitAttachment = seat:FindFirstChildOfClass("Attachment")
						for _,v in pairs(character:GetDescendants()) do
							if v:IsA("MeshPart") or v:IsA("Part") or v:IsA("UnionOperation") then
								if v.Name ~= "HumanoidRootPart" then
									v.Transparency = 1
								end
							end
							if v.Name == "nametagGUI" then
								v.Enabled = false
							end
						end
					else 
						return
					end		
				end)
			end
		end)

I added a .DescendantAdded function.

Code:

-- CharacterAdded (on every respawn or kill, this run everytime)
player.CharacterAdded:Connect(function(character)
	local humanoid = character:WaitForChild("Humanoid")
	humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	
	if not character:IsDescendantOf(workspace) then
		character.AncestryChanged:Wait()
	end

	-- Attachment for Shooting Tower
	wantedShoot = Instance.new("Attachment")
	wantedShoot.Name = "wantedShoot"
	wantedShoot.Parent = character:WaitForChild("HumanoidRootPart")

	-- CanCollide Accessory
	for _,b in character:GetDescendants() do
		if b.Name == "Handle" then
			b.CanCollide = false
		end
	end
	
	character.DescendantAdded:Connect(function(b)
		if b.Name == "Handle" then
			b.CanCollide = false
		end
	end)
	
	-- Enable Backpack
	event3:FireClient(player,true)

	-- Send Event to Reset Player Data Local
	event2:FireClient(player)

	-- Set Avatar to Blocky R15
	local CurrentDescription = humanoid:GetAppliedDescription()

	CurrentDescription.Torso = 0
	CurrentDescription.LeftArm = 0
	CurrentDescription.RightArm = 0
	CurrentDescription.LeftLeg = 0
	CurrentDescription.RightLeg = 0
	humanoid:ApplyDescription(CurrentDescription)

	-- Enable Chat
	local PlayerGui = player.PlayerGui
	local DiedGui = PlayerGui:WaitForChild("chatGUI")
	DiedGui.Enabled = true

	-- Car Seat
	humanoid.Seated:Connect(function(active,seat)
		if seat == nil then
			if exitAttachment == nil then return end
			for _,v in pairs(character:GetDescendants()) do
				if v:IsA("MeshPart") or v:IsA("Part") or v:IsA("UnionOperation") then
					if v.Name ~= "HumanoidRootPart" then
						v.Transparency = 0
					end
				end
				if v.Name == "nametagGUI" then
					v.Enabled = true
				end
			end
			character.PrimaryPart.CFrame = exitAttachment.WorldCFrame
			exitAttachment = nil
			return
		end
		if seat.Name == "DriveSeat" then
			seat:SetNetworkOwner(player)
			exitAttachment = seat:FindFirstChildOfClass("Attachment")
			for _,v in pairs(character:GetDescendants()) do
				if v:IsA("MeshPart") or v:IsA("Part") or v:IsA("UnionOperation") then
					if v.Name ~= "HumanoidRootPart" then
						v.Transparency = 1
					end
				end
				if v.Name == "nametagGUI" then
					v.Enabled = false
				end
			end
		else 
			return
		end		
	end)
end)

I tried it but without success. Maybe it’s because the collision group is on default? Didn’t work with it much.

If you delete (for debugging) the player’s accessories, are they able to enter?

Yes, of course, because then it’s just the raw character. But I don’t understand Roblox why you can’t set the cancollide to false despite the correct code

After hours of searching, I found a comment that definitely answers the problem, but it will be stupid to fix it with CollisionsGroup because then I only have to add all the parts and meshes to a separate group for the accessories so that they don’t collide.

I still found a solution myself. Unfortunately, I can’t say whether this is good for the game and performance.

But what exactly did I do?

  1. Create two CollisionsGroups. One (Accessorys) is for the character’s accessories and the second (AllPartsMeshes) is for all parts, unions, meshes, etc.

  1. Add the objects to the appropriate groups using a server script.
-- First Code to Add All Parts and Meshes to CollisionGroup
for _,c in pairs(workspace.build:GetDescendants()) do
	if c:IsA("MeshPart") or c:IsA("BasePart") or c:IsA("Part") or c:IsA("UnionOperation") then
		c.CollisionGroup = "AllPartsMeshes"
	end
end

-- on CharacterAdded Function
for _,b in pairs(character:GetDescendants()) do
	if b:IsA("MeshPart") or b:IsA("BasePart") then
		if b.Parent:IsA("Accessory") then
			b.CollisionGroup = "Accessorys"
		end
	end
end

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