How can I kill all entities of a specific type, EXCEPT the youngest one?

How can I kill all entities of a specific type, EXCEPT the youngest one? - Man in Blue Polo Shirt Using Black Laptop Computer

I want to create armor stands whenever I stand on a certain block, but when I stand on it, it summons a lot of armor stands.

I tried /kill @e[type=ArmorStand,c=!1] to kill all except the newest one but it killed all of them.

What should I do to remove all except the youngest?



Best Answer

Make a scoreboard

/scoreboard objectives add age dummy age

put a commandblock by a fill clock and type in

/execute @e[score_age=0,type=ArmorStand] ~ ~ ~ /scoreboard players add @e[type=ArmorStand] age 1

put another commandblock by a fill clock and type in

/kill @e[type=ArmorStand,score_age=2]



Pictures about "How can I kill all entities of a specific type, EXCEPT the youngest one?"

How can I kill all entities of a specific type, EXCEPT the youngest one? - Man in Black and Brown Camouflage Shirt Drinking From a Can
How can I kill all entities of a specific type, EXCEPT the youngest one? - Book On A White Wooden Table
How can I kill all entities of a specific type, EXCEPT the youngest one? - Books On The Table



How do you delete specific entities in Minecraft?

Examples
  • To kill the player executing the command: kill @s.
  • To kill the player Steve: kill Steve.
  • To kill item entities: kill @e[type=item]
  • To kill all entities within 10 blocks: ...
  • To kill all entities except players: kill @e[type=!player]
  • To kill all creepers within 10 blocks:


  • Is there a command to kill all hostile mobs?

    Minecraft @ command specifies the entity. If you are trying to kill every mobs in different Minecraft Biomes except yourself, type the command /kill @e[type=! player].



    Kill Command Explained




    More answers regarding how can I kill all entities of a specific type, EXCEPT the youngest one?

    Answer 2

    Just kill all the armorstands before you summon a new one

    Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

    Images: Erik Mclean, Matheus Bertelli, Ylanite Koppens, Ylanite Koppens