Minecraft – How to increase a scoreboard objective if player is at specific coords and has a specific item in his inventory

minecraft-commandsminecraft-java-edition

I don't know how to put those two conditions together into one command. I tried

/scoreboard players add @a{Inventory:[{id:"minecraft:iron_ingot"}]} [x=-506,y=56,z=-1176,r=1] Score 1

but it doesn't work, and I have trouble with brackets.

Best Answer

Your whole command is invalid.
The correct format would be

/scoreboard players add <player> <objective> <count> [dataTag]

so your command would then become:

/scoreboard players add @a[x=-506,y=56,z=-1176,r=1] Score 1 {Inventory:[{id:"minecraft:iron_ingot"}]}

Always remember: NBT data tags always come last in a command.