How to Count Mobs in Minecraft
Minecraft Java Edition 1.21+ and 26+ (Scoreboard + Commands)
In this tutorial, you will learn how to count mobs in Minecraft using a scoreboard and commands in Minecraft Java Edition 1.21+ and 26+. This method is perfect for mob farms, custom maps, automatic counters, and systems that detect how many mobs exist in the world or inside a specific area.
Let's start by creating a scoreboard
scoreboard objectives add mobs dummy
To display the scoreboard on the sidebar, use this command
scoreboard objectives setdisplay sidebar mobs
I will add zombies to the scoreboard using the following command
execute store result score Zombies mobs if entity @e[type=zombie]
Just change it to the mobs you want. You can summon mobs with tags and pull them into the scoreboard through the tag, just test it out