Latching an output for 2 ultrasonic sensors

Well I got it to a point where it was working but it only reversed and went the full way if you covered the first sensor the whole time it travelled back to the second sensor, so I was testing as much as I could... If my programming is a bit scruffy, like I said I've been messing with both my programming and my circuit to try and get the second half to work how I want it to but it just wasn't happening. I might have pasted a scuffed version so I apologise. I figured you'd get the gist of what I was doing and might have a suggestion