-
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.
-
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.