ApplyDescription not removing some accessories when called

Context

For my game, I have NPCs of developers in the team, and I wanted to automatically change the NPC look to match the developer’s new look should they update their avatar at any point in time.

Issue

When calling the script provided below, some accessories DO get removed while other accessories stay (this isn’t just for accessories, as Shirt and Pants have the same issue)

not entirely sure what’s going on here but…

I also tried to make my own function to clear the character’s appearance as well though it’s still running into issues where the NPCs of my character work fine, while everyone else’s NPCs have no accessories or anything applied to them.

Note

The NPCs that are in the game are originally fetched with AlreadyPro’s plugin

local Players = game:GetService("Players")

local NPCHolder = SomeModel -- Model filled with NPCs here

function ClearAppearance(NPC)
    for _, Obj in ipairs(NPC:GetChildren()) do
        if Obj:IsA("Shirt") or Obj:IsA("Pants") or Obj:IsA("Accessory") then
            Obj:Destroy()
        end
    end
end

function UpdateCharacters()
    for _, NPC in pairs(NPCHolder:GetChildren()) do
        local UserSuccess, UserID = pcall(function()
            return Players:GetUserIdFromNameAsync(NPC.Name)
        end)
        if UserSuccess then
            local DescSuccess, HumanoidDesc = pcall(function()
                return Players:GetHumanoidDescriptionFromUserId(UserID)
            end)
            if DescSuccess then
                ClearAppearance(NPC)
                NPC.Humanoid:ApplyDescription(HumanoidDesc)
            end
        end
    end
end

UpdateCharacters()

while wait(32) do
    UpdateCharacters()
end

This issue is the result of using both the HumanoidDescription system as well as manually editing the assets on the character.

As stated on the HumanoidDescription System reference docs:

  • The system assumes the current HumanoidDescription for a character is not manually edited and reflects the current assets on the character.
  • Changing the assets on a character while also using the HumanoidDescription system could lead to undefined behavior.

Rewriting your ClearAppearance function to use the HumanoidDescription system should solve the issue:

local emptyDesc = Instance.new("HumanoidDescription")

local function ClearAppearance(NPC)
    NPC.Humanoid:ApplyDescription(emptyDesc)
end

[ Also ]

I have tried using the ApplyDescription alone, however as mentioned above

The manual clearing was added AFTER I saw that is happening, though that too did not help.

After further testing, with @Grargror 's help, I found what’s happening here:

Since I initially added the NPC’s with the plugin, the accessories were already on the character and they matched with the HumanoidDescription Properties, HOWEVER… Since it was added in via plugin the Description itself was never set to the NPC’s Humanoid, so the existing accessories are there without the humanoid being aware of them.

This was pretty tricky to find because some accessories were actually being removed (like my back accessories and such) but others weren’t…

I’m not sure if this should remain in this category (if it’s a bug or not) but the Humanoid should definitely clear out everything no matter if the Description has been set or not :eyes:

Thanks for the report! We’ve filed a ticket to our internal database and we’ll follow up here when we have an update for you.

1 Like