Cloning a character and using a for i to disable cancollide wont work, why?

if char then

		for i=1,5 do 
			local clone : Model = char:Clone()

			for _, part in ipairs(clone:GetChildren()) do
				if part:IsA("BasePart") then
					clone.PrimaryPart.Transparency = 1

					part:ClearAllChildren()
					part.CanCollide = false
					part.CanTouch = false
					part.Massless = true
					part.Anchored = true
				end
			end

			clone:PivotTo(origin.CFrame * CFrame.new(0,2,0))
			clone.Parent = workspace.Effects
			
			task.wait(.05)
		end
	end

This is the code i use when i dash, it should position it correctly and remove cancollide, for some reason everything works except cancollide (Only for arms and legs), please tell me why?

Result:

There’s probably a humanoid state change happening in the clone. When humanoid state changes, the CanCollide properties of the bodyparts are automatically updated, which means the values you set are overwritten by the engine and you have to set them again.

local function doOtherChangesToBodyparts(charClone)
	for _, part in ipairs(charClone:GetChildren()) do
		if not part:IsA("BasePart") then
			continue
		end
		part:ClearAllChildren()
		part.CanTouch = false
		part.Massless = true
		part.Anchored = true
	end
end

local function setCanCollideOfBodypartsToFalse(charClone)
	for _, part in ipairs(charClone:GetChildren()) do
		if not part:IsA("BasePart") then
			continue
		end
		part.CanCollide = false
	end
end

if char then
	for i=1,5 do 
		local clone : Model = char:Clone()

		clone.PrimaryPart.Transparency = 1

		doOtherChangesToBodyparts(clone)
		setCanCollideOfBodypartsToFalse(clone)
		clone.Humanoid.StateChanged:Connect(function()
			setCanCollideOfBodypartsToFalse(clone)
		end

		clone:PivotTo(origin.CFrame * CFrame.new(0,2,0))
		clone.Parent = workspace.Effects
			
		task.wait(.05)
	end
end
2 Likes

I don’t know if this will work, but i just used CollisionGroups, and set them accordingly so i can’t collide with it, thats pretty much it.

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