This might be your culprit. The continue should be a break, otherwise it just restarts the loop over until NUMBER_OF_ATTEMPTS.
Also for debug purposes, you should always at least print errors returned by pcall. It might make it more confusing if you just consume errors and assume there’s no user error.