Minecraft execute if scoreboard value = 0 with command blocks

Viewed 848

I want to make command blocks that executes "say Zero pigs alive" when the amount of pigs on the map is zero. I made a pig count with a scoreboard on the side that shows the amount of pigs when I press on the button, but I want a command to be executed when the amount is zero on the scoreboard. Does anyone know how I can do this? enter image description here

This is what is looks like, when the 16 is a zero, so no pigs are in the map, it needs to activate the next command block that says "Zero pigs alive"

1 Answers

Yes , this is possible. You would want to do something along the lines of

execute if score test pig matches 0 run say Zero pigs alive

But, you can check if there are no entities alive and say your message all in one command, which would be more efficient. An example would be

execute unless entity @e[type=pig] run say Zero pigs alive```
Related