How to make a character not CanCollide?

So im making a pet system which is going good, everything seems to be doing fine but my pet seems to be Collidable even after disabling CanCollide for all its BaseParts.
https://gyazo.com/9ef5562c9782fe840ec0485ed72aa048

this is what i did to disabled CanCollide

--char has been indexed btw

if char:FindFirstChild("Pet") then char.Pet:Destroy() end
		local ex = game.ServerStorage.EX:Clone() -- a character model that will follow the player
		ex.Name = "Pet"
		ex.HumanoidRootPart.CFrame = part.CFrame
		for i,v in pairs(ex:GetDescendants()) do
			if v:IsA("BasePart") then
				v.CanCollide = false
			end
		end

No errors show up when this is run. I even checked the explorer during testing and sure enough all baseparts are not CanCollide, but it still acts as if its still CanCollide. Is there something im missing? Any help would be appreciated

1 Like

:thinking:
Is it a server script or a LocalScript? Changes like this done through a client script won’t replicate to the server.

That cannot be the ‘entire code’ you posted, as for the clone you make, you never set its ex.Parent.

So either you are not showing us enough of your actual script code, or something else is going on, which cannot be determined from what you have written.

1 Like

@pewpie12302die All these processes are run with server scripts.

@Decker004 yes i didnt show the entire code sorry. heres the entire script:

game.Players.PlayerAdded:Connect(function(p)
	p.CharacterAdded:Connect(function(char)
		char.AncestryChanged:Wait() -- necessary because it makes an error without this line o.O
		
		local part = Instance.new("Part")
		part.Size = Vector3.new(1,1,1)
		part.Transparency = 1
		part.Massless = true
		part.CanCollide = false
		part.Anchored  = false
		part.Name = "PetTarget"
		
		local motor = Instance.new("Motor6D")
		motor.Part0 = char:WaitForChild("HumanoidRootPart")
		motor.Part1 = part
		
		motor.Parent = char.HumanoidRootPart
		part.Parent = char
		
		local anim = Instance.new("Animation")
		anim.AnimationId = "rbxassetid://4765764913"
		local petanim = char.Humanoid:LoadAnimation(anim)
		petanim.Looped = true
		petanim:Play()
		
		--example pet
		if char:FindFirstChild("Pet") then char.Pet:Destroy() end
		local ex = game.ServerStorage.EX:Clone()
		ex.Name = "Pet"
		ex.HumanoidRootPart.CFrame = part.CFrame
		local followscript
		for i,v in pairs(ex:GetDescendants()) do
			if v:IsA("Script") and v.Name == "FollowScript" then
				followscript = v
			end
		end
		for i,v in pairs(ex:GetDescendants()) do
			if v:IsA("BasePart") then
				v.CanCollide = false
			end
		end
		if followscript ~= nil then
			ex.Parent = char
			followscript.Disabled = false
		end
		local idle = Instance.new("Animation")
		idle.AnimationId = "rbxassetid://4765812512"
		local idleanim = ex.Humanoid:LoadAnimation(idle)
		idleanim.Looped = true
		idleanim:Play()
	end)
end)

You could use physics service to disable collisions between your character and pets.

Try to make the pet not collidable with surroundings with collision groups.

Humanoids forcibly turn CanCollide on, so your best bet is to use collision groups to solve the problem.

Create a separate collision group for your pets that doesn’t collide with anything else, and then use PhysicsService:SetPartCollisionGroup on all the parts in your pet to get the same effect

12 Likes

I searched it up on the developer hub and the article mushed my brain…

Can i have some synopsis on how it works?

This worked! thank you :slightly_smiling_face:

1 Like