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

  • 1
    The command OP suggested seems like the most logical one that I could think of. Does anybody know why it doesn't work?
    – Manchineel
    Commented Aug 20, 2019 at 14:20
  • /kill @a[name=!bearb001] works fine for me, it doesn't kill me. I didn't test it with multiple players though, but /kill @e[name=!bearb001] killed 140 entities, I survived that command. May I ask what your username is? If you don't want to tell it publicly, then does your name have anything special? Maybe white space, or some unusual characters like ö, ß, Å, etc.
    – user232393
    Commented Aug 20, 2019 at 15:26
  • @bearb001 I don't think those characters can be included in usernames.
    – 65_7a
    Commented Aug 20, 2019 at 21:40

5 Answers 5


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>


EmeraldEye's answer works, but it removes all information on what team someone was if teams were used already. You could instead use tags, but there is an even easier way, in one command:

/execute at <player_name> as @a unless entity @s[distance=0] run kill @s

This is easy to write, but hard to understand. What this does is first shifting the execution position to the player you want to not kill, but still executing as whatever executes the command (a command block for example). Then it changes the execution context to be done by all players, without changing the position where it executes. It also splits up all further parts of the command, so that they run once per player. Then it checks if the selected player has distance 0 from the execution position (which is still the one player's position that you don't want to kill) and if they do not have distance 0, they get killed.
The advantage of checking for distance 0 and negating the selection is that it also selects people in other dimensions, unlike something like if entity @s[distance=0.001..] would do.

Keep in mind that this command will not kill players that are on the exact same position as the player you don't want to kill. But that can only happen in rare situations like respawning, dismounting a minecart at a fixed position, teleporting, … and then not moving before the other player does the same.

  • You are right. This answer is much easier to write and it works really well.
    – 65_7a
    Commented Aug 20, 2019 at 21:39

you could make something like:
give everyone who shouldn't be killed the tag dontkillme via
/tag <playername> add dontkillme
and then run
/kill @a[tag=!dontkillme]
then every player who doesn't have the dontkillme tag will be killed.


/kill @e[type=Player,name=!playerName] should do the trick

  • Even simpler, @p[name=!<playername>] seems to work fine in Minecraft 1.20. Commented Aug 24, 2023 at 19:44

I think you can use Doing /kill @e[type=!Player] kill all entities non players.And run it a second time to delete dropped item entities.

  • I think the person who asked the question wanted to kill all players except for himself. I don't think he wanted to kill all entities except for players.
    – 65_7a
    Commented Aug 20, 2019 at 10:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .