At this point I think you need to post the ENTIRE script so that we can see where the error is coming from if you don't have the current training to debug it on your own.

We can only offer so many suggestions without seeing the complete code.

You can run the script yourself with the /d switch and step through it and see if you can find the error and what might be causing it too.