Minecraft – Vanilla Minecraft – Detect various /trigger outputs

minecraft-commandsminecraft-java-edition

On multiplayer in Minecraft, I am trying to detect when a player changes their score using /trigger. Here's an example scenario:

I create a new objective called "test." Then, I use /scoreboard players enable @a test, which lets everyone modify the objective.
After which, I have a /tellraw command used on all players giving them four options to click. Each option corresponds to a different score the player gives themselves. For example, clicking on "test one" would make the player run /trigger test set 1, clicking on "test two" would make them run /trigger test set 2, and so on.

How would I be able to detect when a player set their objective to a specific number score, such as 3?

Best Answer

You can use scoreboard in player selectors to find out which one they clicked. Usually this is done by either testfor or execute.

I recommend a 20 t/s clock to check these as soon as they click it. You don't have to use one, but it may help. great method to setup one.

In the case of testfor, it is actually not recommended to use it. You can't exactly distinguish which player clicked it, you just know that it was clicked. A better way is the execute method. Never-the-less, the command should look like this:

Testfor @a[score_test=1,score_test_min=1]

You will need a comparator to get if it succeeded to find it. You should also have a separate command block for each, then change the 1 to another number for each possible outcome.

In the case of execute: recommended method. You can use @p in the command part to target that specific player. Command as follows:

Execute @a[score_test=1,score_test_min=1] ~ ~ ~ <command>

For this, you should set their score of that to 0 as soon as the command is run, otherwise that command may be run twice.