Morph acting weird

When a player Morphs into a MeshPart, it acts strange, almost as if the HumanoidRootPart is colliding with the Model itself.

Video of the problem:
on the first Model, I can walk normally but on others it just goes crazy

The bug where the Model moves automatically:

This is how the mesh is organized:

This is my CharacterManager ModuleScript:

local CharacterManager = {}

local CharacterData = require(script.Parent.CharacterData)

-- Get character model
function CharacterManager.getCharacterModel(characterModelName)
	local charactersFolder = game.ReplicatedStorage:WaitForChild("Characters")
	local characterFolder = charactersFolder:FindFirstChild(characterModelName)

	-- Verify if character model has been found
	if characterFolder then
		return characterFolder:Clone()
	else
		warn("Folder not found: " .. characterModelName)
		return nil
	end
end

-- Função to equip the character as a Morph (using the entire Model)
function CharacterManager.equipCharacter(player, characterModelName)
	local characterModel = CharacterManager.getCharacterModel(characterModelName)
	if not characterModel then
		warn("Model not found: " .. characterModelName)
		return
	end

	-- Verify if there is a PrimaryPart set
	local primaryPart = characterModel:FindFirstChild("HumanoidRootPart")
	if not primaryPart then
		warn("The Model does not has a PrimaryPart set!")
		return
	end

	-- Define the PrimaryPart to the Model
	characterModel.PrimaryPart = primaryPart

	local playerCharacter = player.Character or player.CharacterAdded:Wait()
	local humanoidRootPart = playerCharacter:WaitForChild("HumanoidRootPart")
	local humanoid = playerCharacter:WaitForChild("Humanoid")

	-- Disable collisiont temporarily
	for _, part in ipairs(characterModel:GetChildren()) do
		if part:IsA("BasePart") then
			part.CanCollide = false
		end
	end

	local playerPosition = playerCharacter.HumanoidRootPart.CFrame
	characterModel:SetPrimaryPartCFrame(playerPosition)

	playerCharacter:Destroy()

	player.Character = characterModel  -- Atualizar a referência de personagem do jogador
	characterModel.Parent = workspace

	-- Grants that new character has the Humanoid correctly set
	local newHumanoid = characterModel:FindFirstChildWhichIsA("Humanoid")
	--[[if newHumanoid then
		newHumanoid.WalkSpeed = 16  -- Ajuste a velocidade de caminhada, se necessário
		newHumanoid.Health = newHumanoid.MaxHealth 
		newHumanoid.PlatformStand = false 
		newHumanoid:ChangeState(Enum.HumanoidStateType.Physics) 
	end]]

	-- Enable collision after morph
	for _, part in ipairs(characterModel:GetChildren()) do
		if part:IsA("BasePart") then
			part.CanCollide = true
		end
	end

	-- Define camera offset if necessarry
	for _, i in ipairs(CharacterData) do
		if i.modelName == characterModelName then
			if newHumanoid then
				newHumanoid.CameraOffset = i.cameraOffset
			end
			break
		end
	end

	print(player.Name .. " fez o morph do personagem: " .. characterModelName)
end

return CharacterManager
1 Like