How to Implement Reset Avatar Function in a Character Customization Feature

  1. What do you want to achieve? I would like to implement a function that will reset the player’s character based on his/her roblox avatar. This is for the Character Customization feature of our game.

  2. What is the issue? and What solutions have you tried so far?

There are two approaches I tried. The first one is using ReplaceBodyPartR15 which I also use to equip the packages retrieved from the Roblox catalog. I first clone the player character and store it in the ReplicatedStorage. When the player opts to reset his/her avatar, I clone the body parts from the cloned player character and use ReplaceBodyPartR15 to apply it to the actual player character. Appearance wise, the character resets as expected. However, I get stuck in the floor and I can’t move. See the recorded video as reference.

Here are the relevant codes for my first approach:

self.PlayerCharacter.Archivable = true
self.OriginalCharacter = self.PlayerCharacter:Clone()
self.OriginalCharacter.Parent = ReplicatedStorage
for i, v in pairs(Enum.BodyPartR15:GetEnumItems()) do
	local partPrefab = nil

	if v.Name == "RootPart" then
		partPrefab = self.OriginalCharacter.HumanoidRootPart
	else
		if v.Name ~= "Unknown" then
			partPrefab = self.OriginalCharacter[v.Name]
		end
	end

	if partPrefab then
		local part = partPrefab:Clone()

		if v.Name == "RootPart" then
			part.Parent = workspace
			part.CFrame = self.PlayerRootPart.CFrame
		end

		self.PlayerHumanoid:ReplaceBodyPartR15(v.Name, part)
	end
end

The other approach I tried was to use Humanoid description. However, only the head gets replaced and the other body parts remained as is.

The relevant code that I used for the 2nd approach are just two lines:

local humanoidDescription = Players:GetHumanoidDescriptionFromUserId(self.UserId)
self.PlayerHumanoid:ApplyDescription(humanoidDescription)

As an additional note. All the relevant scripts I posted are running in the server side. I also read a few posts that are somewhat relevant to the issue I am encountering but the solution is already similar to what I have tried.

Can someone please recommend which approach is more recommended and how to resolve the corresponding issue of the approach? I prefer the ReplaceBodyPart approach as it works with no issues when I use it to equip packages/bundles from the Roblox catalog but I am open to suggestions. Thank you very much.

HumanoidDescriptions are the much better approach. Have you set the body part ids in the description that you’re applying? It should be able to replace body parts using them. If you did, maybe the ids aren’t the right ones? They are a bit tricky to find sometimes.

1 Like

Oh, so using the GetHumanoidDescriptionFromUserId is not enough? Ok, I’ll search on how to get the part ID’s and report back here for the result. Thanks for the suggestion. :grinning:

So I tried setting part ID’s explicitly using the Mesh ID’s of my parts.

local humanoidDescription = Players:GetHumanoidDescriptionFromUserId(self.UserId)

for i, v in pairs(Enum.BodyPartR15:GetEnumItems()) do
	if v.Name == "UpperTorso" then
		humanoidDescription.Torso = self.OriginalCharacter[v.Name].MeshId
	elseif v.Name == "LeftUpperArm" then
		humanoidDescription.LeftArm = self.OriginalCharacter[v.Name].MeshId
	elseif v.Name == "RightUpperArm" then
		humanoidDescription.RightArm = self.OriginalCharacter[v.Name].MeshId
	elseif v.Name == "LeftUpperLeg" then
		humanoidDescription.LeftLeg = self.OriginalCharacter[v.Name].MeshId
	elseif v.Name == "RightUpperLeg" then
		humanoidDescription.RightLeg = self.OriginalCharacter[v.Name].MeshId
	end
end

self.PlayerHumanoid:ApplyDescription(humanoidDescription)

The model is not exactly what I expected. It seems it uses the default blocky parts.

Not sure if I did it correctly. I just use the upper body parts as the BodyPart attributes of the Humanoid description don’t match the parts of the R15 Rig. I had the impression that getting the Humanoid Description through GetHumanoidDescriptionFromUserId will suffice. :frowning_face:

This might be late but incase if you havnt found a solution, HumanoidDescription is a good way to go
This post will help you:
https://devforum.roblox.com/t/humanoidapplydescription-not-working-as-intended/931846