Best way to add or equip items to a HumanoidDescription?

I guess I should learn more about it, but a quick question: is there really a function to equip/add items to a humanoid automatically?

That is, something like:
HumanoidDescription:SetItem(id, itemType, assetType)

Example:
HumanoidDescription:SetItem(6984769289, Enum.AvatarItemType.Asset, Enum.AvatarAssetType.ShirtAccessory)
roblox

I don’t think there is a feature as such, but it would be great if it existed so I wouldn’t have to create a complete equipment system specifying how to add each item, I don’t know if that’s the best way.

7 Likes

You can achieve this through InsertService:LoadAsset() and Humanoid:AddAccessory().

local InsertService = game:GetService("InsertService")

local function giveAccessory(humanoid: Humanoid, assetId: number)
	local Accessory = InsertService:LoadAsset(assetId):GetChildren()[1]
	humanoid:AddAccessory(Accessory)
end

giveAccessory(...)
3 Likes

Thanks for answering!

I currently use that method to load and equip accessories, but it only adds the accessories to the character and doesn’t put them in the HumanoidDescription. So I’m looking for something that actually equips those accessories by their id in the humanoid so I can load it later easily with :ApplyDescription() (All these items are from the catalog) And so that the player can later edit the order of his layered clothing

You can just edit the HumanoidDescription then.

--[[ Server Script ]]--

local Players = game:GetService("Players")
local MarketPlaceSerivce = game:GetService("MarketplaceService")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid: Humanoid = character.Humanoid

		---
		local ACCESSORY_INDEX = {
			[8] = "HatAccessory",
			[41] = "HairAccessory",
			[42] = "FaceAccessory",
			[43] = "NeckAccessory",
			[44] = "ShouldersAccessory",
			[45] = "FrontAccessory",
			[46] = "BackAccessory",
			[47] = "WaistAccessory",
		}
		local function addAccessory(description: HumanoidDescription, accessoryId: number)
			local info = MarketPlaceSerivce:GetProductInfo(accessoryId)
			if not info then warn("Accessory ID is not valid") return end

			local AccessoryType = ACCESSORY_INDEX[info.AssetTypeId]
			if description[AccessoryType] == "" then
				description[AccessoryType] = "" .. accessoryId
			else
				description[AccessoryType] ..= ",".. accessoryId
			end
		end
		---

		local HumanoidDescription = humanoid:GetAppliedDescription()
		addAccessory(HumanoidDescription, 9305847750)

		humanoid:ApplyDescriptionReset(HumanoidDescription)
		
		local descriptionWithAccessories = humanoid:GetAppliedDescription()
		-- Do something with this
	end)
end)
5 Likes

Thank you! I forgot to say that parameters like id, itemType and assetType are not a problem to get in the script, I’m just looking for a good method to equip any asset in HumanoidDescription, but I think it should be specified if it is a t-shirt, a bodypart and everything when Roblox could add something that does this automatically. Well, I appreciate your help and I’ll post again when I resolve the issue!

I already solved this a long time ago, sorry for leaving this post empty!
I think I will post this again in the future but as a suggestion for Roblox

here the game:

and thanks to those who contributed, especially @TheMrShowerMan