In addition to what Rob and SGS have said, don’t forget the number 1 reason for running into the “more than 60 upvalues” error:
Is it possible you have an “end” missing somewhere? 99% of the time that I hit this error, it’s because an “end” is missing somewhere.
The indenting on the code is a bit all over the place (and I don’t even know if this is the whole lua file) so it’s not easy for me to check it.