How To Plug Detected Light Values into Variables and Still be Usable in Programs in EV3-G
First guess: the wait for button command is bad practice.  Well, not the whole thing, just the use of the middle button.  The reason is that that button is also used to start the program.  The program may be jumping past the wait for and saving to "Midpoint" before humans notice that the program has started. Try any other brick button.