The commands will have the command block type, and order they should be in. the top few are in chat commands for those who dont know.
In chat:
give @s command_block
scoreboard objectives add c dummy
scoreboard objectives add c2 dummy
scoreboard objectives setdisplay sidebar c
Command blocks:
Scoreboard players reset * c | Repeating cmd block
Scoreboard players set @e[type=(mob)/(space_name)] c2 1 | Chain cmd block
scoreboard players operation "count" c += @e[type=(mob)] c2
scoreboard players reset @e c | chain cmd block
make sure to have all chain command blocks powered or always active. Put the commands I gave in the order from top to bottom. Make sure chain command blocks are right next to the repeating command block where it is facing and facing the same direction. Anyone who needs help just ask.
![](https://i.ytimg.com/vi/zzYWCUJWluo/maxresdefault.jpg)