How do I run a summon command based on the amount of HP the main mob has?

I have tried many lines of code, and none of them seem to work. This is the code I use to store the health score:

execute as @e[type=zombie,limit=1] at @s store result score @s Health run data get entity @s Health

This is the code I use to check if it's equal to or under a certain amount and summon the mob:

execute if score @e[type=zombie,limit=1] Health matches ..20 run summon minecraft:wither_skeleton -106 80 -30

None of the command blocks work, and they don't even have a log output. How do I run a summon command based on the amount of HP the main mob has?

1 Answer

Check the following:

Are the command blocks being activated? The command block for the first command should be Repeating.

Is the zombie selected in the second command the same zombie that was selected in the first?

Make sure the Health scoreboard is a dummy scoreboard (/scoreboard objectives add Health dummy).

You Might Also Like