Help checking if player is wearing accessory

I’m trying to detect if the player is wearing the “Pal Hair”.

Here’s my code:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAppearanceLoaded:Connect(function(char)
		for _, v in pairs(char:WaitForChild("Humanoid"):GetAccessories()) do
			print(v)
			
			if v.Name == "Pal Hair" then
				print("yes")
			else
				print("no")
			end
		end
	end)
end)

The problem I’m facing is that if the player is wearing a second accessory (for example, a hat) then the script will also print “no”

The script is great at detecting if the player is wearing the “Pal Hair” I just need help making it so that it only searches for the Pal Hair and nothing else.

1 Like
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAppearanceLoaded:Connect(function(char)
		if char:FindFirstChild("Pal Hair") then
			print("Yes.")
		else
			print("No.")
		end
	end)
end)

No need to loop, a simple if statement should suffice.

3 Likes

If you want it to stop checking once it’s detected “Pal Hair” in your array, just use break somewhere near where you put print("yes") and that will break the loop and it will continue to the next block of code out of the loop.