Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to Implement Reset Avatar Function in a Character Customization Feature?

Asked by 3 years ago

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.

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.

https://drive.google.com/file/d/1iNu2ET_KspL3W-pAAe3bquUFh2_8VqCM/view?usp=sharing

Here are the relevant codes for my first approach:

This is for caching the original state of the player's character model.

self.PlayerCharacter.Archivable = true
self.OriginalCharacter = self.PlayerCharacter:Clone()
self.OriginalCharacter.Parent = ReplicatedStorage

This is for replacing the body parts with the ones from the cloned original character model.

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.

https://drive.google.com/file/d/1IWUSb0m0_gS9z2akO4yBSTyUfrnryBVL/view?usp=sharing

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.

One user from Roblox developer forums suggested to assign body part ID's in the humanoid description before applying. I can't find a straightforward answer to how to get the body part ID's as the parts in the description don't match the ones from a R15 rig.

Can someone please recommend which approach is better 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.

Answer this question