Minecraft – detect when anybody kills a zombie

minecraft-commandsminecraft-java-edition

I need to know how to detect if a player kills a zombie so I can finish my game where zombies attempt to attack a castle and you have to defend it. I want to make so that when you kill 50 zombies you win the game.

if this is possible please tell me how to do it.

Best Answer

You can add an objective of type stat.killEntity.Zombie, which will keep track of how many zombies the player has killed:

/scoreboard objectives add KillZombie stat.killEntity.Zombie

You can select people who have killed 50 zombies with @a[score_KillZombie_min=50]. For example, to teleport them somewhere:

/tp @a[score_KillZombie_min=50] X Y Z