Problem with scoreboard finding named and enchanted item

So I have a scoreboard but I want it to make sure it only detects a certain item which is named and enchanted but I keep getting this error:

[22:35:51] The dataTag does not match for 6b9d7006-4945-46d3-92a3-1d183c1f666d

My current commands:

/scoreboard players add @e[type=Item] nightVeil 1 {Item:{tag:{display:{Name:"Night's Veil",ench:[{id:22,lvl:1}]}}}}
/execute @e[type=Item,score_nightVeil_min=1,score_nightVeil=1] ~ ~ ~ /execute @e[r=1] ~ ~ ~ /effect @p minecraft:invisibility 45 0
/kill @e[type=Item] {Item:{id:"minecraft:leather_chestplate"}}

Also for the last command I want it too also delete this certain Item but I can't find a way to do so.


Solution 1:

The error message might not be too useful since, when receiving it via a command block, it only concerns the last iteration of the command. In this case, the last item entity that had its NBT data checked. If the item you want found is indeed found, but there's another item lying around somewhere that's next in line to check, the error is going to be about that incorrect item even though the command was actually successful.

That being said, the id and lvl tags for enchantments have the datatype "short", assuming that you're targeting an item that was enchanted normally or provided to the player with the correct datatypes. As well, the ench tag itself does not go inside the display compound.

You might also run into an issue by adding 1 to its score instead of setting their score to 1. If the other commands are not run in the same tick after /scoreboard runs, then the score might end up being set to 2 or higher, and thus will never be found later on.

/scoreboard players set @e[type=Item] nightVeil 1 {Item:{tag:{display:{Name:"Night's Veil"},ench:[{id:22s,lvl:1s}]}}}

You do not need a nested /execute command, especially one that targets all entities and not just the player you're trying to target. Just move the parameters into the selector in /effect.

/execute @e[type=Item,score_nightVeil_min=1,score_nightVeil=1] ~ ~ ~ /effect @p[r=1] minecraft:invisibility 45 0

/kill does not support NBT data. If you were intending to target the item from before, you can target it based on its score you had already given it:

/kill @e[type=Item,score_nightVeil_min=1,score_nightVeil=1]

If you were intending to target a different item altogether, you need to give it a score of its own based on its NBT data and then /kill based on its score, just as you've done already.