How to detect a certain mob

minecraft-commandsminecraft-java-edition

I am creating a map and I want to make it so that when to defeat a zombie boss, a lever appears that sends you to the next level. Right now, I am trying:

/execute unless entity @e[type=zombie,distance=14] run /setblock -409 146 -208 lever

However, with this command, it activates the /setblock command even if the zombie is not defeated. How should I fix this?

Best Answer

The issue seems to be that the command you listed triggers ONLY if the mob is exactly 14 blocks away.

In order to fix this, change the command by adding a .. in front of the 14. This means "select if the mob is at 14 blocks or less"

/execute unless entity @e[type=zombie,distance=..14] run setblock -409 146 -208 lever

As DisplayNameNotFound's answer says, it's always good practice to remove that second slash.