Error messages are your friends. Post the exact error message and post the line where the error occurs including any relevant context to that line.
I agree with Bam.
I recommend installing an addon like BugSack/!Buggrabber. This addon helped me a lot in detecting/finding errors on my script.
Unfortunately, it won't tell you the error of in your logic. :D