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.
This is caused by scoreboard team formatting. The display names obtained from the selector will be stylized separately if the target is in a team. Since the formatting options of the display names are being set at their own depth, it overwrites formatting inherited from the parent, being color
, bold
, italic
, underlined
, obfuscated
, and strikethrough
(all defaulting to false without a third-party NBT editor to modify the prefix in the scoreboard.dat file and color
is defined by the team option).
As well, insertion
, hoverEvent
, and clickEvent
will be overwritten no matter if the target is in a team or not. However, clickEvent
will only be overwritten for player display names and not non-player display names.
You will either have to remove the player from the team before running the command or wait before adding them to the team until after the command runs.
Best Answer
You have two things missing or wrong.
"text":"Kill all people?""color":"green"
is invalid JSON - it's missing a commaclickEvent
uses the actionrun_command
to execute commandsTaking both into account this will work assuming you're using the latest version of Minecraft:
/tellraw @a {"text":"Kill all people?","color":"green","clickEvent":{"action":"run_command","value":"/kill @a"}}