Getting an accessory/hat asset ID from the actual hat object

Is there a good way to do this? My idea is to call Players::GetCharacterAppearanceAsync and to compare the accessory that the character is wearing with each item in the returned model from that function, but is that really the best way to do it?

2 Likes

I think the mesh id is the same as the hat id basically search such hat for a mesh then get the id from the mesh id and that should be the hat id

No, I don’t think those Ids would be the same.

The Accessory is one Id

The Mesh is one Id

The Decal/Texture is one Id

2 Likes

If that’s the case then I don’t think it’s possible to get the ID from the hat unless you had a humongous data store with all IDs and such

Could you use GetCharacterAppearanceAsyncInfo? You could then get the AssetId of each item worn by the following;

local info = game.Players:GetCharacterAppearanceInfoAsync(21482650)
for i,v in ipairs(info['assets']) do
	local AssetId = v.id
	print(AssetId)
end

If needed, you could then LoadAsset() each AssetId and compare the names based on that? That’s the only way to do it as far as I know.

4 Likes

Yes but the problem is that Roblox Interns who makes the Accessories are lazy and sometimes don’t rename the item in game so keep that in mind. (Basically the names don’t match with the name on the web or could have the same name with a different Asset)

but instead of comparing the Names you can compare other stuff like the MeshId and TextureId. (Well same problem with Mesh Id because Roblox reuses Meshes and just Retexture them so it might be ideal to check the Texture instead)

3 Likes

There is no definite way (that I know of) to do this. The next best thing I could do is get the name of the object said player is wearing and the MeshId and TextureId.

local player = game:GetService("Players"):GetCharacterAppearanceAsync(14491710)

for _, asset in pairs (player:GetChildren()) do
	if asset:IsA("Accoutrement") then
		print(asset.Name)
		local Mesh = asset:FindFirstChild("Handle"):FindFirstChildOfClass("SpecialMesh")
		if Mesh then
			print(Mesh.TextureId)
			print(Mesh.MeshId)
		end
	end
end

--[[
	---Would Print---
	
	KittyEars
	http://www.roblox.com/asset/?id=413143035 
	http://www.roblox.com/asset/?id=1374148
	TieOBC
	http://www.roblox.com/asset/?id=29447249
	http://www.roblox.com/asset/?id=28463033
--]]
player:Destroy() --Remove even though its Parented to nil.
2 Likes

Will the accessory part always be named “Handle” and will the mesh always be a SpecialMesh? I assume the answer to the second question is a yes but I am unsure about the first.

…Not to be that guy, but I don’t think interns are the ones who make catalog items. From what I understand based on some previous posts, they have a real team and a sophisticated planning process for catalog items.

2 Likes

Oh ok, I just assumed that Roblox Interns make them because I saw there Script in Gears.

I still stand corrected about who ever makes the Accessories are lazy, because they don’t rename the item to match the name on the Catalog.

Though, let’s look at the issue this way:

  • Catalog item names are not unique
  • Asset ids are unique

To OP;
I really suggest to use Players::GetCharacterAppearanceInfoAsync, as CodeSleepRepeat suggests earlier in this thread. It contains the asset ids, which can be used to get the actual asset (i.e. accessory object), but you can’t really do it the other way around.

For example, some hats or hairs might be copies of each other, just having a different texture - in that case, it’s not too unimaginable to think that the accessories would have the same name for their Accessory object, and keeping track of every possible accessory meshid & textureid will be an enormous task - there are several thousands of those. :cold_sweat:

The pros of using the asset id is that it can be used to:

  • Get the catalog information about the accessory
  • Get the Accessory instance in-game for the accessory

And having the desired player’s user id makes it easy, which OP already seems to have for their use-case.

2 Likes

The part in the Accessory will Almost always be “Handle” I have yet to see a part that isn’t named “Handle”

Sorry for the bump. I’ve come across this issue and thought I’d share my code for anyone else facing the same problem who might end up coming here as I did.

The result:

image

Simply get these values in code with

local assetType = Tool:GetAttribute("AssetType")

Sorry if I bothered anybody.

1 Like