BGG user hoembla found a bug in the script. I have attached a version that works, but I'm not very happy with the solution.
The problem is that your dead groups are supposed to be removed at the end of your turn, not matter if you have a move available or not. The way I had made it, you only removed dead groups after having made a placement. But then there could be situations where you had no placement available, so you didn't remove your dead groups. I tried a few different things, but the only thing I could get to work was this: