Getting id of accessory from a npc

So I am trying to get the id of a hat and other accessories in roblox studio through code, but how am I supposed to go about doing this?

Btw this is r15 and a npc in the game

Does the NPC have a HumanoidDescription instance contained within it?

Well, you could just go into the npc with a script, check if it actually has accessories like

local accessory = NPC:FindFirstChildOfClass("Accessory")
if accessory ~= nil then
-- do whatever you need with the accessory id
end

Or, like @Forummer said, if the NPC has a humanoiddescription inside of it, you can check if that exists and if it has accessory id’s inside.

The Humanoid:GetAccessories() function should help out, just get the humanoid of the NPC and run that function. The article on the devhub about the humanoid is here. It will return an array of accessories that the NPC has on.

Humanoid:GetAccessories() just gets an array of the humanoid’s accessories, that won’t get information about those accessories though.

As far as I know you cant get the ID of an accessory since most of these are placed like models they dont have an ID property like shirts or pants or Tshirts, May I ask why you need the IDs?, If you want them to load the NPC’s accesoriees into something else or store them you could just clone it and store it or parent it to wherever you need it to be.

You can go into the Accessory’s Handle (what parts are usually named inside of an Accessory), go inside of that part and find the MeshId inside of the Mesh.

yes but that isnt the direct accessory thingy, And also changing the mesh could mess with the way its placed since of the handles of attachments and I think all hats are positioned differently

I didn’t say to change the mesh, i just meant accessing the mesh so you could get the id.

The main issue I find with this thread is that the poster wont explain why he needs the ID, the solution he is looking for could be something else thats easier, So we really dont know I assumed the wholee changing mesh because Im assuming he wants to load them or something.

1 Like