Can anyone help me with layered clothing here? I’m trying to prompt save avatar and remove any unowned layered clothing from humanoid description before saving it, but accessoryblob is not accessible with scripts so im having a hard time
local function SaveAvatar(player)
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rigType = humanoid.RigType
local humanoidDescription = humanoid:WaitForChild("HumanoidDescription")
local robloxDescription = Players:GetHumanoidDescriptionFromUserId(player.UserId)
local equippedEmotes = {}
if not robloxDescription then
print("HumanoidDescription not found!")
end
local emotes = robloxDescription:GetEmotes()
for name, ids in pairs(emotes) do
equippedEmotes[name] = ids
end
-- Process emotes if available
if emotes then
for emoteName, emoteInfo in pairs(emotes) do
if type(emoteInfo) == "table" and #emoteInfo > 0 then
local emoteId = emoteInfo[1]
emotes[emoteName] = {emoteId}
table.insert(equippedEmotes, emoteName)
end
end
end
humanoidDescription:SetEmotes(emotes)
humanoidDescription:SetEquippedEmotes(equippedEmotes)
local unownedCount = 0
local newDescription = humanoidDescription:Clone()
local assetTypes = require(game.ReplicatedStorage.Information.AssetTypes)
local newAccessoryBlob = {}
local function removeUnownedItems(assetTypeString, assetId)
if assetTypeString == 'ShoulderAccessory' then
assetTypeString = 'ShouldersAccessory'
elseif assetTypeString == 'Hat' then
assetTypeString = 'HatAccessory'
end
if newDescription[assetTypeString] then
local accessoryList = newDescription[assetTypeString]
if accessoryList and accessoryList ~= "" then
local updatedAccessories = {}
for id in string.gmatch(accessoryList, '([^,]+)') do
if tonumber(id) ~= assetId then
table.insert(updatedAccessories, id)
end
end
if assetTypeString == 'Shirt' or assetTypeString == 'Pants' then
if #updatedAccessories == 0 then
newDescription[assetTypeString] = "0"
else
newDescription[assetTypeString] = table.concat(updatedAccessories, ',')
end
else
newDescription[assetTypeString] = table.concat(updatedAccessories, ',')
end
end
end
end
-- Check and remove unowned layered clothing items
local layeredClothingTypes = {
"JacketAccessory", "ShirtAccessory", "PantsAccessory", "TShirtAccessory", "SweaterAccessory",
"ShortsAccessory", "LeftShoeAccessory", "RightShoeAccessory", "DressSkirtAccessory"
}
for _, accessory in ipairs(humanoidDescription:GetAccessories()) do
local ownsAsset = MarketplaceService:PlayerOwnsAsset(player, accessory.AssetId)
if ownsAsset then
table.insert(newAccessoryBlob, {
Order = accessory.Order,
AssetId = accessory.AssetId,
Puffiness = accessory.Puffiness or 1.0,
AccessoryType = accessory.AccessoryType
})
else
unownedCount = unownedCount + 1
end
end
-- Apply the updated accessory blob to the humanoid description
humanoidDescription:SetAccessories(newAccessoryBlob)
-- Loop through all children of the UnownedScrolling frame
for _, Frame in pairs(UnownedScrolling:GetChildren()) do
if not table.find({'UIGridLayout', 'Template'}, Frame.Name) then
local assetId = tonumber(Frame.Name)
local unownedAsset = MarketplaceService:GetProductInfo(assetId)
local assetTypeString = assetTypes[unownedAsset.AssetTypeId]
if assetTypeString then
unownedCount = unownedCount + 1
removeUnownedItems(assetTypeString, assetId)
end
end
end
-- If there are unowned items, send a notification
if unownedCount > 0 then
forwardInfoNotif:FireServer("You do not own " .. unownedCount .. " items from your current outfit. Unowned items will not be equipped on your Roblox avatar.", false, "UnownedItemsError")
end
-- Prompt to save the avatar
AvatarEditorService:PromptSaveAvatar(newDescription, rigType)
end