Minecraft kill all players except a certain player


I'm making a house, with a security system, where only I am allowed. My command block is supposed to kill all players except me, but I can't find what command to use. I've tried /kill @a[name=!<My username], but it doesn't work. What is the actual command

Best Answer

You can use the scoreboard teams feature.

First, create a team: /scoreboard teams add <name>
Then, add the player you don't want to kill to the team: /scoreboard teams join <team> <player>
Finally, kill the everyone apart from the team: /kill @a[team=!<team name>]

So if you wanted to kill everyone except for team Arqade which had you in it, you would do:
/scoreboard teams add Arqade
/scoreboard teams join Arqade <Your Username>
/kill @a[team=!Arqade]
Replacing '<Your Username>' with your in-game Minecraft username.

If you want to remove someone from a team, you do /scoreboard teams leave <player>