In Minecraft, I'm making an adventure map and doing a dungeon style thing. After you die in the "dungeon", I want all mobs in that specific area to die so the player can try again.

I've tried doing a testfor command but nothing seems to work.

  • How about just when they respawn, there's a pressure plate or command block to check if player's nearby, then kill all mobs?
    – MCMastery
    Commented Nov 3, 2017 at 15:08
  • 1
    Reason for voting to reopen: All answers on that other question use /testfor, which no longer exists. Commented Dec 30, 2019 at 6:09
  • It would be better to have a new question that addresses the removal of /testfor. This question is still a duplicate for a version that did have that command working still, thus people searching for 1.8 that find this question would be lead back to the correct answer.
    – NBN-Alex
    Commented Dec 30, 2019 at 19:33
  • Questions with outdated answers do not cease to be valid duplicate targets.
    – pppery
    Commented Dec 31, 2019 at 16:05

2 Answers 2


You first have to create a scoreboard like this:

/scoreboard objectives add deaths deathCount

Then you put a repeating, always active command block somewhere out of sight (but still in the loaded area), containing this command:

/execute at @a[scores={deaths=1..}] run kill @e[type=!player,distance=..10]

And in the direction the repeating command block is facing put an always active chain command block (can be conditional if you make it face the same way) containing this command:

/scoreboard players set @e[scores={deaths=1..}] deaths 0

This kills all entities except for players in a radius of 10 around the dead player.

  • Would that be in the area they would respawn or in the area where the mobs were?
    – Comyak
    Commented Nov 3, 2017 at 10:00
  • It's at the death location. The player location is set to the respawn location as soon as they click "respawn", but since this runs 0,05s after the death, the player probably didn't click that yet, especially because the buttons need a bit of time to become clickable. Commented Nov 3, 2017 at 10:37
  • Did you already publish the map and link to this question? I'm getting an unusual amount of upvotes. It's my second most upvoted answer on this site (5th most upvoted post overall) and that in just 5 hours. Commented Nov 3, 2017 at 15:27
  • 2
    @Fabian this question got into Hot Network Questions (HNQ) bar which is shown on the right side on all SE sites. It means more exposure and more upvotes (due to association bonus rep).
    – antimo
    Commented Nov 3, 2017 at 18:26
  • 2
    That's not a point of consistency, it's a point of actually working. @a selects all players, @e selects all entities. It's intended how it is. Commented Nov 3, 2017 at 22:08

You could use scoreboard objectives...

/scoreboard objectives add youDied deathCount
The deathCount will automatically increase when someone dies.

Now you can run a clock to test for it:
/testfor @a[score_youDied_min=1]
(1 = one death, you could as well use a higher number to grant them multiple lives before it resets)

The command to kill the mobs is /kill @e[x,y,z,r,type=!Player] and don't forget to reset the death count:
/scoreboard players set @a youDied 0

  • He wants to kill all entities in an area, so you have to use execute instead of testfor. Commented Nov 3, 2017 at 9:54
  • @Fabian yep I forgot about the kill radius, but wouldn't /kill @e[x,y,z,r,type=!Player]work as well?
    – dly
    Commented Nov 3, 2017 at 10:09
  • Only if you knew the coordinates of the player before writing that command. Commented Nov 3, 2017 at 10:35
  • probably in the dungeon, which is known :P (radius can be applied as well)
    – dly
    Commented Nov 3, 2017 at 10:53
  • Ok, but it's still more effort and one command block more. If you want fixed coordinates, you can just use execute @a[score_deaths_min=1] 12 34 56 <command>. Commented Nov 3, 2017 at 10:57

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