getNearest() result can't be used with indexOf()?

You have a mistake on the variable definition:

var peons = this.getByType(‘peon’);

if(peon[0]){

You define “peons”, but you are calling “peon”

I hope that helps,