Please, use code=lua tags when posting code. It wraps your code in a nice box, and gives line numbers, which are important for the next part.
Though I'm likely no help with this code, providing the exact error your getting, all lines of it, will help anyone trying to help you.
It will also specify line numbers near the error.