For those who want the script working now, before @rfindley has had time to implement a proper fix, feel free to use this updated version.
It contains a temporary workaround that makes it possible to submit answers again:
When the original script has been properly fixed, I’d recommend switching back to that version.