Command to set block based on item presence
I am currently trying to figure out how to get this command
execute if entity @p[distance=.11,nbt={SelectedItem:{tag:{display:{Name:"{\"text\":\"key\",\"color\":\"white\",\"bold\":\"true\"}"}}}}] run setblock -191 21 -52 minecraft:redstone_block
to work with an arrow renamed as "key" and then it in theory should open a Iron door that is nearby, just by being near it. However anytime I get close to the Iron door, nothing seems to change. I also have this command
execute unless entity @p[distance=.11,nbt={SelectedItem:{tag:{display:{Name:"{\"text\":\"key\",\"color\":\"white\",\"bold\":\"true\"}"}}}}] run setblock -191 21 -52 minecraft:stone_bricks
for when someone is near the area but without the item. That seems to work fine.
Can someone explain this to me? I am very confused in how to get it to work.
I'm using Minecraft 1.14.3.
You have a typo in your commands, instead of .11 you need to put ..11 for it to work. Also ensure you are running this in a Repeat Command Block set to Always Active.
Correct First Command:
execute if entity @p[distance=..11,nbt={SelectedItem:{tag:{display:{Name:"{\"text\":\"key\",\"color\":\"white\",\"bold\":\"true\"}"}}}}] run setblock -191 21 -52 minecraft:redstone_block