Although it should still work, you don't need to use else if you are returning. Return essentially just stops reading the function, so if %target isn't an object, then it will be returned, and the rest of the function wont be ran.
As to how to make a script auto-execute; simply put it into a folder or zip file named Script_NAME, change Script to a more suitable name, however only certain types are recognized, and change Name to whatever you want it called. Try to keep it unique so other add-ons don't overwrite it. Then name the file server.cs, or client.cs if its a client sided piece of code, and Blockland will automatically execute it when the server starts (assuming its enabled), or when you start up Blockland (for client.cs).
The reason it crashed when you added the exec at the end is because it executed itself, which then executed itself, which then executed itself, etc, causing an infinite loop.