If npcs.closest returns null, and you try to call interact on it, it will throw this error.
Null check it! i.e
target = npcs.closest("Elvarg");
if (target!=null && target.interact("Attack")) {
// do stuff
}
Also, when you post code, please use the provided code formatting tool in the reply box; so that it's (more) readable.
There are a host of other improvements that can be made on your code; but soon enough you will find these out when your script misbehaves!
GL!
Apa