Applying LayeredClothing on a NPC through Client

You can write your topic however you want, but you need to answer these questions:

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

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

Is the preview NPC being created on the server or on the client?

Client

asfdfkmacasdqweqwesfczxc

ApplyDescription can only be called from the server, not from the client.

How did it work on the first screenshot then? Furthermore wouldn’t that throw an error? The print line did work on the pcall block?

No idea. This is the error I got from the pcall you added.


1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.