How to properly change a player's character appearance, and why you shouldn't use HumanoidDescriptions

[EDIT (8/15/21)] This thread is now outdated. Before now, there was a memory leak associated with HumanoidDescriptions. It has now been fixed and you will not have to use this method to change a player’s character appearance.

Background
The other day, I was looking to set change a player’s character appearance, and I was pointed in the direction of HumanoidDescriptions, which is an easy way to view what a player’s character is wearing and method of changing their appearance.

Problem
After some experimentation, and implementing HumanoidDescriptions to my game, I noticed significant spikes in server ping. The server ping got so bad that at some points, it was reaching 1000-2000ms+. At first, I figured it was just my coding, but after analyzing and rewriting anything that I might’ve thought could be the culprit, the server ping was still EXTREMELY high. My last resort was to relook at how player’s characters were being changed, as I noticed that server ping was spiking as player’s characters were being modified. Just after modifying that, server ping was back to its normal ~100-120ms, and today (after more reworking), it was hitting at max 80ms.

Solution
My solution is as follows:

-- old code (simplified for ease of reading)
local character = player.Character
local desc = script.HumanoidDescription

character.Humanoid:ApplyDescription(desc)

-- new code (also simplified for ease of reading)
local model = script.Dummy-- a character model with a desired appearance

local animate = player.Character.Animate
plr.Character = model:Clone() 
animate.Parent = player.Character

In the original code, you can see that I was using HumanoidDescriptions, as shown on the developer hub, and even with that, it was still causing enormous amounts of lag in my game. With the new code, I created a character model with the desired appearance for my players, added the original character’s Animate script to it, and then set the player’s character to that new character model.

I couldn’t find any other resources on how to properly set a player’s appearance, and I still see people recommending HumanoidDescriptions to others.

SOME OTHER NOTES:

  • Server ping remained high, even after the characters that had HumanoidDescriptions applied were destroyed.
  • Animations broke frequently when using HumanoidDescriptions.
  • As HumanoidDescriptions were being applied, the server ping was hitting its peak.

I would’ve liked to post this in #bug-reports , as I see this as a larger issue. The developer hub doesn’t make any note of dropped performance when using HumanoidDescriptions at all, and after searching on this forum, I noticed that I wasn’t the only one experiencing this issue.

9 Likes

You should report this issue as an engine bug on the forum rather than falling back to less-than-ideal solutions like this one.

6 Likes

I don’t have access to #bug-reports, which is why I didn’t post there. I posted this as a resource for others in the meantime, as I didn’t want other developers to end up using HumanoidDescriptions, which would result in problems mentioned in the OP. In addition, while this is a bit more work than using a HumanoidDescription, it is in no way “less-than-ideal” considering the circumstances.

If I wanted to change the appearance of three different players with this method, it would take ~.00174 seconds. Using HumanoidDescriptions, it would take ~.175 seconds.

4 Likes

Am I missing something?

This would only work if you knew the preset look you were trying to go for. This will not work for avatar systems where there are tons of combinations possible.

Great observation, and with that, I say ‘Challenge accepted’. While difficult, it isn’t impossible. I whipped this up for you to show how I would do something like this. I left some documentation to hopefully guide anybody through my thought process.

I didn’t add functionality to change your skin tone, but I left the pseudo-code to show it is very possible. I made the code change your head’s color to pink, and made a note about how to fix that on the client.

I think that even if I were to do this with HumanoidDescriptions, I would have to do something fairly similar (send a table of information to the server, and then have it plug said information into the HumanoidDescription).

something that i want to emphasize: this is not complete code. it’s meant to show that it is possible to modify player’s appearances without HumanoidDescriptions. i would not use this in your game, and i would only use it as a guide on how to implement something like this into your game. :slight_smile:

1 Like

i’ll make a ticket and look into this memory leak issue. Does anyone have a simple rbxl test place file they can give me which i can run to repro the issue?

4 Likes

@unix_system made a very good point in a previous post, which might help you figure out the source of the problem.

I made what he wrote into a place-- the ‘Main’ script will print out the number of nil instances:
https://www.roblox.com/games/7105788502/HumanoidDescription-nil-instances

I originally found this problem when I was trying to change player’s appearances and then teleporting them onto a map. The original time this took was ~.1355 seconds, and the people helping me test immediately started reporting lag.

Clip to show ~.1355 seconds to load in three players w/ HumanoidDescriptions:

After removing HumanoidDescriptions, spawn time DRASTICALLY decreased-- loading three players in ~.0005 seconds:

Something to note: lag didn’t just occur when players spawned in-- it was residual even after the humanoid that the description was applied to was destroyed.

5 Likes

a fix has now been put in for the memory leak, along with some other optimizations

4 Likes