Updated:
How it works
- Create a scoreboard objective of type
trigger. - Enable it for players.
- A player runs
/trigger name, which raises their score. - A command block sees the score, does the real action (such as a teleport) and resets the score to 0.
Players can only change their own score, so this is a safe way to give them actions.
A "back to lobby" command
Setup (an operator runs it once):
/scoreboard objectives add lobby trigger
In a repeating command block (always active) and chain command blocks:
scoreboard players enable @a lobby
execute as @a[scores={lobby=1..}] run tp @s 0 64 0
scoreboard players set @a[scores={lobby=1..}] lobby 0
Now anyone can type /trigger lobby to go to 0, 64, 0.
Why enable is needed
A trigger turns itself off after one use. Without scoreboard players enable the second try says the trigger is not enabled, which is why the first line re-enables it every tick.
Clickable chat menu
| Version | Command |
|---|---|
| Java 1.21.5 and later | /tellraw @a {text:"[Back to lobby]",color:"aqua",click_event:{action:"run_command",command:"/trigger lobby"}} |
| Java 1.21.4 and earlier | /tellraw @a {"text":"[Back to lobby]","color":"aqua","clickEvent":{"action":"run_command","value":"/trigger lobby"}} |
Clicked text can only run commands the player could type themselves, which is why /trigger works for everyone.
Choices with numbers
/trigger shop set 2
set puts the score to a number, so one trigger can offer several choices: shop=1 for a sword, shop=2 for a bow, handled with execute as @a[scores={shop=2}] run ….
Common problems
- "You cannot trigger this objective yet": run
scoreboard players enableevery tick. - Invalid objective: it must be created as type
trigger, notdummy. - It runs again and again: reset the score to 0 after the action.
- Bedrock Edition: there is no /trigger.
Check your command
The Command Error Doctor checks common syntax mistakes in your browser.