When debugging a script, the flowchart below might be helpful - serving as a checklist - in finding possible errors in the script.
On the left side are the error categories shown, on the right side actions that can be executed to track the error or decrease the chance for errors.