Minecraft – why does the scoreboard not work

minecraft-commandsminecraft-java-edition

I'm working on a system to detect right clicks using a villager and than trigger several commands. I'm using an always active repeating commandblock to start a chain of commandblocks which run the commands I need them to run. I've setup a scoreboard objective called torchLever and set it to:

minecraft.custom.talked_to_villager

so it increases everytime I talk to a villager.

I'm now trying to see if a player has the value of the scoreboard set to 1 with this command

/execute as @p if score @s torchLever matches 1.. run say hi

however this does not seem to work. I've tested a few different commands like the one in this article but that doesn't work either.

How can I see if there is a player with the torchLever score set to 1 and than start executing a bunch of commands?

Best Answer

First off, your objective is a synax error. The correct way is:

/scoreboard objectives add torchLever minecraft.custom:minecraft.talked_to_villager

As can be seen on the minecraft wiki (https://minecraft.gamepedia.com/Scoreboard#Objectives).

Secondly, your execute command is needlessly complicated. Though it may seem pretty simple at first glance, there is an even simpler and more efficient way to execute players with a score, or many scores:

execute as @a[scores={torchLever=1..}] run say hi

As can be seen on the minecraft wiki (https://minecraft.gamepedia.com/Commands#Usage, scroll down to "target selector arguments).

Since you didn't specify what version of minecraft you're using, I assumed it was 1.13 Java Edition.