"CanCollide = false" is not working for cloned character

Hello,

I want to make a character which is in the player character (HumanoidRootPart) but it must be CanColide off. The problem is that the character is still cloning, so when CanColide in the script is set to false, it changes to true anyway. How can I make the character, clone only once and the positions of the character will change with the player character?

(The character keeps cloning as one model and not another, the script is in the player character)

local character = game.ReplicatedStorage.character:Clone()

while wait() do
	local playerPositionX = script.Parent.HumanoidRootPart.Position.X
	local playerPositionY = script.Parent.HumanoidRootPart.Position.Y
	local playerPositionZ = script.Parent.HumanoidRootPart.Position.Z
	character.Parent = game.Workspace
	character.CanCollide = false
	character.CFrame = CFrame.new(playerPositionX, playerPositionY, playerPositionZ)
end

Thanks in advance!

is the local character a part or a model?

What is the “character”? (Model, Part…)

like @patopro77 said, use CanCollide instead of CanColide

heres a script example:

local character = game.ReplicatedStorage.character:Clone()

while true do
    task.wait()
	character.Parent = game.Workspace
	character.CanCollide = false
	character.CFrame = script.Parent.Humanoid.CFrame
end

By the way, use task.wait() to avoid lag and don’t use “while wait() do” or “while task.wait() do” to avoid bugs, allways do

while true do
    task.wait()

(If worked, the solution go to @patopro77 because him that found the problem)

This is a model, but I realized I need to refer to each part separately (e.g. character.LeftFoot.CanCollide = false) but something like this happens:

If I remember correctly, humanoids prevent their root part from having a can-collide of false and will force set it back to true. You might need to get a recreation of the character (one that uses meshes instead of letting the humanoid round the parts) Unless it doesn’t work like that for r15 in which case just get rid of the humanoid.

Removing the humanoid helps, but something like this happens:

image

(My game uses R6)

Create a CollisionGroup.
Set the CollisionGroup’s Collisions to false.
Set all parts in the Character to that CollisionGroup.

For more info on Collision Groups, you can find that here.

1 Like

The character should not collide with anything (as I understand well Collision Groups means that the character does not collide with e.g. a player only)

If you want to change the collision value, you need to select each part of the character and set CanCollide to false. To do this, you would need to run it in a RunService RenderStepped or Heartbeat, depending on the script you’re using. If you’re using a regular server-sided script, you would use Heartbeat, if you are using a localscript, you would use RenderStepped. Now, this shoud look something like this.

game:GetService("RunService").Heartbeat:Connect(function() -- assuming this is server sided
     for _, v in pairs(character:GetChildren()) do
           v.CanCollide = value
           -- To check that this actually works, we will print the value
          print(v.CanCollide)
     end
end)

You can set Collision Groups to collide with nothing. In the collision group editor that is done by unchecking all the boxes.

4 Likes

Thank you very much, you helped me a lot!

For a complete the answer you will need to also anchor the primary part (ie. HumanoidRootPart in most cases) otherwise the humanoid (mesh model or part r15) with disabled collisions will fall through the floor:

local humanoid =  script.Parent:WaitForChild("Humanoid")
local humanoidRootPart = humanoid:WaitForChild("HumanoidRootPart")

function BaseMob:disableCollision()
	-- loop through all humanoid and disable collision
	if not humanoid then return end
	humanoidRootPart.Anchored = true
	for _, part in pairs(humanoid.Parent:GetDescendants()) do
		if part:IsA("Part") or part:IsA("MeshPart") then
			part.CollisionGroup = "Dead"
		end
	end
end

In this case I configured a collision group called “Dead” with all collisions disabled
image

1 Like