Updated:
1. Setup (run once)
/scoreboard objectives add vote trigger
/scoreboard objectives add votes dummy "Votes"
/scoreboard objectives setdisplay sidebar votes
Non-operators can change a trigger objective with /trigger. See the trigger command.
2. Open the vote
/scoreboard players set @a vote 0
/scoreboard players enable @a vote
/tellraw @a [{"text":"Pick the next game ","color":"yellow"},{"text":"[A] Tag","color":"aqua","click_event":{"action":"run_command","command":"/trigger vote set 1"}},{"text":" "},{"text":"[B] Hide and seek","color":"green","click_event":{"action":"run_command","command":"/trigger vote set 2"}}]
A trigger is disabled again after one use, so each player gets one vote. On 1.21.4 and older use clickEvent and value instead of click_event and command.
3. Count the votes
# repeat, always active
execute store result score A votes if entity @a[scores={vote=1}]
# chain, always active
execute store result score B votes if entity @a[scores={vote=2}]
See execute store.
4. Announce the winner
execute if score A votes > B votes run title @a title {"text":"A wins!","color":"aqua"}
execute if score B votes > A votes run title @a title {"text":"B wins!","color":"green"}
execute if score A votes = B votes run title @a title {"text":"Tie","color":"gray"}
Run these once when the vote closes (title and tellraw).
5. Reset
/scoreboard players reset @a vote
/scoreboard players set A votes 0
/scoreboard players set B votes 0
Troubleshooting
- Clicking does nothing: run the
enableline first. - Second click errors: that player already voted. Enable them again to allow a change.
- Bedrock: there are no triggers or chat buttons; use two command blocks with buttons instead.
Check your command
The Command Error Doctor checks common syntax mistakes in your browser.