minecraftminecraft-commands

Minecraft execute if scoreboard value = 0 with command blocks


I want to make a command block 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?

scoreboard screenshot saying "pig 16"

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"


Solution

  • 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```