You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve?
→ Applying LayeredClothing on a NPC through Client. The reason as to why I am trying to do this on client is because I want to create a preview NPC that only the client is supposed to see in like a showcase of sorts that they have unlocked something. -
What is the issue?
→ The script that applies layered clothing resets the given HumanoidDesciption whenever :ApplyDescription() method is called. However this only happens for some NPCs. Sometimes it works, sometimes it does not.
the NPCs are Descendant of workspace and NPCs are Preloaded through ContentProvider
The code block which executes to apply the layered clothing:
function LayeredClothingArmor.setLayeredClothingEquipped(player, character, layeredClothingId, equipped)
if not player then
if RunService:IsClient() then
ContentProvider:PreloadAsync({character})
end
local humanoidDescription: HumanoidDescription = character.Humanoid:GetAppliedDescription()
local original = humanoidDescription:GetAccessories(false)
local newList = removeTopsFromAccessoryList(original)
table.insert(newList, {
Order = 10,
AssetId = layeredClothingId,
AccessoryType = Enum.AccessoryType.Jacket,
IsLayered = true
})
if RunService:IsClient() then
print(`Description before SetAccessories:`, humanoidDescription:GetAccessories(false))
end
humanoidDescription:SetAccessories(newList, false)
if RunService:IsClient() then
print(`Description after SetAccessories:`, humanoidDescription:GetAccessories(false))
end
task.spawn(function()
pcall(function()
character.Humanoid:ApplyDescription(humanoidDescription)
if RunService:IsClient() then
print(`Description after ApplyDescription:`, character.Humanoid:GetAppliedDescription():GetAccessories(false))
end
end)
end)
return true
end
I am aware of the pcall, however :ApplyDescription doesn’t seem to throw any errors as the line of code below it still runs. I went through couple of posts on DevForum, they seem to suggest that the NPC must be completely loaded before Applying Description, wouldn’t PreloadAsync achieve that?
Here are the images and output I have gathered.
When LayeredClothing got applied properly:
When it did not get applied properly:
My initial guess was that AccessoryType was wrong, however the same code run on the server seems to work (and an image of how it is supposed to look on the second NPC)