Solution
If you are using Global Variables with references, the mechanical actions
Switch Until Released and
Latch Until Released will not work properly.
Use instead the other 4 mechanical actions for buttons (Switch When Pressed, Switch When Released, Latch When Pressed, Latch When Released).
Right-click on a button, go to the Mechanical Action section, and select them from the options mentioned above: