How do I detect accessorry?

How can I detect if player wear certain accessorry by IDs or something?
Thanks.

You cant get the specific id of an accessory although u can get the Mesh id of the handle of the accessory using this script. (Note: You have to get the MeshId of the item u want and put it in the brackets where it says id) and (put the code you want to execute where there is lines in the middle)

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
for i, v in pairs(character:GetChildren()
if v:IsA("Accessory") then
if v.Handle:FindFirstChild("Mesh") then
if v.Handle.Mesh.MeshId == "id" then
---------------
end
end
end
end
end)
end)

This would be an easier way:

						for Parent, Child in pairs(player.character:GetChildren()) do
							if Child:IsA("Accessory") then
								local Handle = Child:FindFirstChild("Handle") 
								if Handle then
-- for an example
									Handle.Material = Enum.Material.Plastic

if you’re trying to detect a specific id, u can add an if statement or use @ReplicaService script

This is not what he’s doing, he’s trying to get the MeshId of an accessory.

He said hes trying to detect an accessorry. he was asking "by ID’S or something?’
Looks like it, not sure.

I think you’ll be able to do that with Players | Roblox Creator Documentation.
Assets sub-table will include: id, assetType & name.

Alright. I edited this a bit because I wanted to find face too.
Correct me if im wrong:

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
for i, v in pairs(character:GetChildren()
if v:IsA("Decal") then
if v.Handle:FindFirstChild("face") then
if v.Handle.Decal.Texture == "https://www.roblox.com/asset/?id=8329438" then
print("works fine")
end
end
end
end
end)
end)

Thanks!

the decal isn’t a children of Head where the actual face decal is stored

That won’t work. You can just use this foolproof method instead, which uses tables so that you can add as many face IDs or hat mesh IDs that you want. Just put it in a script inside ServerScriptStorage and edit the tables at the top with your asset IDs.

local HatMeshIDs = {4529120548, 5144431334}
local FaceIDs = {8329438, 7317691}

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		repeat wait() until Player.Character
		repeat wait() until Player:HasAppearanceLoaded() == true
		for i,v in pairs(Character:GetChildren()) do
			if v:IsA("Accessory") and v:FindFirstChild("Handle") then
				local Handle = v:FindFirstChild("Handle")
				for i,id in pairs(HatMeshIDs) do
					if Handle:FindFirstChildOfClass("SpecialMesh").MeshId == "rbxassetid://"..tostring(id) then
						
						--This is where u do stuff to the hat
						print("Found hat from table")
						
					end
				end
				
			end
			if v.Name == "Head" and v:FindFirstChildOfClass("Decal") then
				for i,id in pairs(FaceIDs) do
					if v:FindFirstChildOfClass("Decal").Texture == "http://www.roblox.com/asset/?id="..tostring(id) then
						
						--This is where u do stuff to the face
						print("Found face from table")

					end
				end
			end
		end
	end)
end)

To find the hats mesh ID, clicked the ‘Linked Items’ tab on the hat’s profile and then click the ‘RenderMesh’ object shown in that tab


After clicking RenderMesh, you just use the ID shown on the RenderMesh’s page URL instead of the original hats page.

Thanks! I will try it tommorow.

Alright, so I tested script with my hat. The script wont works. It says attempt to index nil with MeshId.
Script:

local HatMeshIDs = {5918020191, 6413023275}
local FaceIDs = {20418518, 8329438}

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		repeat wait() until Player.Character
		repeat wait() until Player:HasAppearanceLoaded() == true
		for i,v in pairs(Character:GetChildren()) do
			if v:IsA("Accessory") and v:FindFirstChild("Handle") then
				local Handle = v:FindFirstChild("Handle")
				for i,id in pairs(HatMeshIDs) do
					if Handle:FindFirstChildOfClass("SpecialMesh").MeshId == "rbxassetid://"..tostring(id) then

						--This is where u do stuff to the hat
						print("Found hat from table")

					end
				end

			end
			if v.Name == "Head" and v:FindFirstChildOfClass("Decal") then
				for i,id in pairs(FaceIDs) do
					if v:FindFirstChildOfClass("Decal").Texture == "http://www.roblox.com/asset/?id="..tostring(id) then

						--This is where u do stuff to the face
						print("Found face from table")

					end
				end
			end
		end
	end)
end)