2

I am trying to test if the player is holding a piece of paper named "Ticket" with a lorestring saying that the ticket is not punched. I have the following:

/testfor @p[r=10] {SelectedItemSlot:0,Inventory:[{Slot:0b,tag:{display:{Name:"Ticket",Lore:[This is a punched ticket.]}}]}

I can get it to work with just the Name but I can't get it to work with both the name and lore. How do I fix this?

3

You are missing a closing curly bracket for the item data:

/testfor @p[r=10] {SelectedItemSlot:0,Inventory:[{Slot:0b,tag:{display:{Name:"Ticket",Lore:["This is a punched ticket."]}}}]}

However, I recommend using the SelectedItem compound tag instead of checking for each individual hotbar slot. SelectedItem will contain a copy of the player's currently-held item (minus the Slot tag), such that you do not need to have multiple command blocks for each slot:

/execute if entity @p[distance=..10,nbt={SelectedItem:{tag:{display:{Name:"\"Ticket\"",Lore:["This is a punched ticket."]}}}}] run <command>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.