Normally this type of error is due to a missing or wrong reference. You are trying to access something via a variable that has no value or the wrong value.
Without any more information, like the relevant code, nobody will be able to help you. Please try to limit the code to the essentials; nobody will read thousand lines of code.
In the meantime you could add checking to your code. So after every “set xxx = [something]” statement check the result for not being “nothing” and give an appropriate error message.
Guessing from your inital message, I can only deduce that there is something wrong with your code. But when you do not know how to debug this (I don’t blame you for this), I would suggest that you get somebody to assist you, who knows about debugging.
This forum is not the place to give you a course in debugging.