I'm looking into it.
it works fine in 0.18.12 (0.18.13 unconfirmed)
As far as I can tell, there is nothing wrong with my code, it's an issue with on_gui_closed event and player.opened = gui. (This lets you close the GUI by pressing E or Escape, or closes it when you open another GUI)
I can try to fix it, but it may be a game bug, not a mod bug.