0

I'm trying to get a testfor command to find a player holding an item named Key2A. I'm in 1.12 and I'm using the command:

/testfor @p[r=100] {SelectedItemSlot:0b,Inventory:[{Slot:0b,tag:{display:{Name:"key"}}}]}

This outputs:

[00:58:14] shmevan8or did not match the required data structure

Could someone help me?

2 Answers 2

2

You don't need SelectedItemSlot when you can just use SelectedItem! Also probably because you were testing for an item named "key", not "Key2A".

/testfor @p[r=100] {SelectedItem:{tag:{display:{Name:"Key2A"}}}}
0

If you want to test for an item and execute a command at a person you will have to type these commands in a repeating command block:

/scoreboard players reset @a Key2A  
/scoreboard players set {PlayerName} Key2A 1 {SelectedItem:{tag:{display:{Name:"Key2A"}}}}  
/execute @a[score_Key2A_min=1,score_Key2A=1] ~ ~ ~ {Your Commands}  

Before you do this you have to add the objectives:
/scoreboard objectives add Key2A dummy

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .