Minecraft – Testfor selected item

minecraft-commandsminecraft-java-edition

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?

Best Answer

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"}}}}