MZ Checking if target is enemy or actor

I'm trying to setup a formula that only affects an enemy.
I’m trying to use the following, which works when you defeat an enemy, but when an Elly is defeated it errors due to the b.enemyId() not existing for an actor

I'm using Formula Effects by HimeWorks

The formula I have so far

if(b.hp == 0) {
$gameVariables.setValue(5, b.enemyId());
$gameSwitches.setValue(3, true);
}
Could you try encapsulating that whole script in

If(target.isEnemy()){

}
That did it, thanks

Original thread: https://forums.rpgmakerweb.com/threads/checking-if-target-is-enemy-or-actor.159593/