Cloned character rig is completely broken

I am trying to use the new avatar creation service to make a game where you create a custom bundle then try it on.

My game has a “Try on” button that

  1. Clones the character into the world
  2. Changes the character to that character

Whenever I change my character it breaks the animations in a crazy way. The character has animations but the arms and legs go way past the body.

Here is what it is supposed to look like:

and here is what happens after my script:

Here is my code used by the try on button:

local function TryOnModel()

local CustomAvatar = LocalPlayer.PlayerGui.CharacterCreatorGui.ViewportFrame.ModelWindow.WorldModel:FindFirstChildWhichIsA("Model")
local modelToPublish =  CustomAvatar:Clone()

local charClone = modelToPublish:GetDescendants()

local NewCharacter = modelToPublish

for _,meshPart in charClone do
	if not meshPart:IsA("MeshPart") then
		continue
	end

	meshPart.Anchored = false
	meshPart.Parent = NewCharacter
end
for _,Part in charClone do
	if not Part:IsA("Part") then
		continue
	end
	Part.Anchored = false
end
for _,humanoid in charClone do
	if not humanoid:IsA("Humanoid") then
		continue
	end
	humanoid.Parent = NewCharacter
end

script:Destroy()
NewCharacter.PrimaryPart = NewCharacter:FindFirstChild("PrimaryPart")
NewCharacter.Name = LocalPlayer.Name
NewCharacter.Parent = workspace



local Camera = workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = NewCharacter

LocalPlayer.Character:Destroy()
LocalPlayer.Character = NewCharacter



local AnimateScript = LocalPlayer.PlayerScripts.Animate
AnimateScript.Disabled = true
wait(0.1)
AnimateScript.Disabled = false

end

Basically it iterates through all the mesh parts, parts, and the humanoid in the GUI and reorganizes them into a new model. That model is put in the workspace. The camera focuses on that new model. Then your character is set to that model.

Lastly, and here is where the issue begins; the animation script for the local player is refreshed. (If I don’t do this the new character isn’t animated)

The animate script is the default one from roblox. Why does it completely break on my newly created character? The animation script works fine before my “try on” tool mangles it into a new model in the workspace.

One thing you should look at is the call you have to script:Destroy(). The code after that shouldn’t run correctly.

I fixed it. I was missing the humanoid rootpart in the model I was cloning. Not having the rootpart meant no root rig attachment so the rig completely broke

1 Like

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