Minecraft – How to detect if a player has a Lime Carpet named “$5”

minecraft-commandsminecraft-java-edition

I'm working on a map, and at one part of it, you have to have a Lime Green Carpet in your inventory (I know the data for that is 14), and then it takes it and removes some blocks using /fill. I was using this:

/testfor @a {Inventory:[{id:<minecraft:carpet>,Damage:<14>s}]}

I got that off another question, but it has to be named: $5

Anyone know what I'm doing wrong? I'm no command expert, so I need some help.

Best Answer

First do into the chat

/scoreboard objectives add Money dummy

Then in a repeating command block have

/scoreboard players set @a Money 0

Then in a chain command block do this command

/scoreboard players set @a Money 1 {SelectedItem:{tag:{display:{Name:"$5"}}}}

And in another chain command block

/execute @a[score_Money_min=1] ~ ~ ~ YOURCOMMANDHERE

And that is how you do it.