Need some logic/syntax help!

Yes, I replaced the IR gate with a push button.

I actually just stumbled upon a work around. I only changed the following code within gapTimer() :

void gapTimer() {
  digitalWrite(ledPin, LOW);
  
    for (int x = 0; x < 500; x++) 
    {
       val2 = digitalRead(7);  
       Serial.println(x);
       
        if (x == 499)
        { 
          digitalWrite(ledPin, HIGH);
          delay(100);
          digitalWrite(ledPin, LOW);
          delay(100);
          digitalWrite(ledPin, HIGH);
          delay(100);
          digitalWrite(ledPin, LOW);
          delay(100);
          digitalWrite(ledPin, HIGH);
          delay(100);
          digitalWrite(ledPin, LOW);
          arrayCounter = 0;
          for (int y = 0; y < 7; y++) // Used to rest all array values back to 0
        {
        gapArray[y] = 0; 
      }
     }
          
        if (val2 == 1) // When sensor is blocked again, stores current x value in array slot incremented by arrayCounter
       {
         Serial.print(x);
         Serial.print(" ");
         gapArray[arrayCounter] = x;
         arrayCounter++;
         break; 
       }
   
    timerSwitchA = 0; // Resets 
    timerSwitchB = 0;
  }
}

This serves to reset the array and counter if there isn't any input for a few seconds (when x reaches 499) and flash the LED a few times to indicate the reset. For some reason when I reset the counter and array in this fashion, it returns back to the start condition and works fine. So, at worst, if an input is received incorrectly, I'll have to wait a few seconds for it to reset. This isn't really what I was wanting, but it seems to work well enough to move forward with checking the intervals against the intended pattern.