While true do statement randomly pausing, plus other bugs

I’ve tried to run the script with all of your suggestions (thanks by the way!), but I’ve encountered this random error that I have no idea why it is there and makes no sense.
Here it is.
EDIT: I’ve fixed this bug now.

if the the issue is solved you should mark someone as the solution