The Event pins do not retain values for long. This script is unstable and should not work properly in most situations - I would expect this to start throwing serious errors eventually.
Store references, promote those pins to vars and use those vars, checking whether they’re valid before you perform any ops.