Issue with Layered Clothing on a script

I have been editing a fairly old ui one of my friends made that allows me to adjust the VertexColor and Texture of any accessory mesh on a person’s avatar, but the moment my character spawns in–my layered clothing disappears entirely. My other accessories remain fine, but my layered clothing is just–poof.

I will not share the rest of the script but this is the beginning part of the script I have. I feel like it’s close to where I think the issue might be. Some help could be appreciated!

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local InsertService = game:GetService("InsertService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local RemoteFolder = ReplicatedStorage.RemoteEvents.FaceAndAccessoryColors

local CachedLoadAsset = (function()
	local CachedAssets = {}

	return function(AssetId)
		local Result

		if CachedAssets[AssetId] then
			Result = CachedAssets[AssetId]:Clone()
		else
			local Original = nil

			local Success, Error = pcall(function()
				Original = InsertService:LoadAsset(AssetId):GetChildren()[1]
			end)

			if Success then
				CachedAssets[AssetId] = Original
				Result = Original:Clone()
			else
				warn("Could not load asset: " .. Error)
			end
		end

		return Result
	end
end)()

Players.PlayerAdded:Connect(function(Player)
	Player:GetPropertyChangedSignal("Character"):Connect(function()
		local Character = Player.Character
		
		if Character then
			local Humanoid = Character.Humanoid --pls
			
			if Humanoid.RigType == Enum.HumanoidRigType.R15 then
				Character.ChildAdded:Connect(function(Child)
					if Child:IsA("Accessory") then
						if Child.Handle.ClassName == "MeshPart" then
							RunService.Stepped:Wait()
							if Child.Parent then
								Child:Destroy()
							end
						end
					end
				end)
				
				local Info
				local Success, Error = pcall(function()
					Info = Players:GetCharacterAppearanceInfoAsync(Player.UserId) --you cannot get the asset ID from the meshparts
				end)

				if Success then
					Humanoid:RemoveAccessories()
					
					for i, Asset in pairs(Info.assets) do
						local AssetTypeName = Asset.assetType.name

						if AssetTypeName == "Hat" or string.find(AssetTypeName, "Accessory") then
							local ReplacementAsset = CachedLoadAsset(Asset.id)

							if ReplacementAsset then
								Humanoid:AddAccessory(ReplacementAsset)
							end
						end
					end
				else
					warn("Could not get character appearance: " .. Error)
				end
			end
		end
	end)
end)

As far as I remember only SpecialMesh instance has VertexColor. (?)
So, probably you are grabbing all the accessories a player has and turning them into a SpecialMesh in order to have access to that property. (?)

So during that process probably you are getting the mesh ID of the accessories to create a SpecialMesh? But when dealing with LayeredClothings that wont work correctly cause maybe the WrapLayer is missing when rebuilding/creating the new accessory?

I think more information is required to find the issue.

You’re exactly correct, actually. I’m turning the accessories into SpecialMesh handles so that VertexColor is possible. Turns out it isn’t possible to do so with Layered Clothing since it can’t do that…I wonder if there’s a way to add a line in regards of it so it doesn’t remove it. :face_exhaling:

The first thing I would try is, grab the WrapLayer from the LayeredClothing Accessory (if exist one, which means is a Layered Accessory), and test if that works under a SpecialMesh, which I dont think it’ll work… but trying is fun!
Do it by creating a new accessory and adding it to the Character/Humanoid, no need to do it in your code.

The WrapLayer in LayeredAccessories has the ID meshCage to fit onto the character mesh. IF that doesnt work… then probably you have no chance and you cant change VertexColors of LayeredAccessories… So your best bet, would be to check if the Accessory in player has a WrapLayer and if it does, do not turn it into a SpecialMesh, and just keep it as it is…
I hope that adding the WrapLayer working with SpecialMesh works… but idk yet, its a matter of testing it…

Just tested this out! Doesn’t work unfortunately. I might need to figure out an alternative for being able to color it later…but for now I need to insure the layered clothing at least stays on the character. Would I need to add a line in regards of excluding MeshParts containing a WrapLayer?

1 Like

Yup, exactly. Exclude the Accessories that has a WrapLayer, do not turn it into a SpecialMesh, just that for the temporary fix.

1 Like

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