Storing IR Sensor value not working This is my first time working on Arduino for my project and I ran into an issue. I'm trying to make a very simple Vending Machine. Coin or any obstacle passes in front of the IR sensor and based on that, the user can either press button 1 or 2 and based on that motor 1 or 2 would run respectively.
The overall logic works exactly how I want it to, the issue I'm facing is that the variable (sensorStatus) storing the IR sensor value isn't working correctly. Whether anything passes in front of it or not, it lets me press the buttons anyways and the motor starts working.
void loop() {

  int sensorStatus;

  //this is where im having the issue
  if (digitalRead(inSensor) == LOW) sensorStatus = LOW;

  if(sensorStatus == LOW) {
      buttonStatus1 = digitalRead(inButton1);
  
      if(buttonStatus1 == HIGH) {
        digitalWrite(relayControl1_1, LOW);
      } else {
        digitalWrite(relayControl1_1, HIGH);
      }
    
      buttonStatus2 = digitalRead(inButton2);
    
      if(buttonStatus2 == HIGH) {
        digitalWrite(relayControl2_1, LOW);
      } else {
        digitalWrite(relayControl2_1, HIGH);
      }

      sensorStatus = HIGH;
   }
}

If I don't use this logic and store the value of the sensor directly into the variable (sensorStatus), the whole program seems to be working till I have an obstacle in front of the sensor continuously. I don't want this to happen, I want it to work in such a way that once an obstacle passes in front of the sensor it keeps the value (even after the obstacle is gone) until a button is pressed and after that, it gets rid of the value to repeat the process once again. It seems to be a code logic issue but I can't seem to figure out the logic behind it.
My Complete Source Code:
const int relayControl1_1 = 13; // relay 1 of 1 (input 1)
const int relayControl1_2 = 12; // relay 1 of 2 (input 2)
const int relayControl2_1 = 11; // relay 2 of 1 (input 3)
const int relayControl2_2 = 10; // relay 2 of 2 (input 4)

const int inButton1 = 9; //input button 1
const int inButton2 = 8; //input button 2

int buttonStatus1 = 0;
int buttonStatus2 = 0;

const int inSensor = 7;

void setup() {
  Serial.begin(9600);
  pinMode(relayControl1_1, OUTPUT);
  pinMode(relayControl1_2, OUTPUT);
  pinMode(relayControl2_1, OUTPUT);
  pinMode(relayControl2_2, OUTPUT);

  pinMode(inButton1, INPUT_PULLUP);
  pinMode(inButton2, INPUT_PULLUP);

  pinMode(inSensor, INPUT_PULLUP);
  
}

void loop() {

  int sensorStatus;

  //this is where im having the issue
  if (digitalRead(inSensor) == LOW) sensorStatus = LOW;

  if(sensorStatus == LOW) {
      buttonStatus1 = digitalRead(inButton1);
  
      if(buttonStatus1 == HIGH) {
        digitalWrite(relayControl1_1, LOW);
      } else {
        digitalWrite(relayControl1_1, HIGH);
      }
    
      buttonStatus2 = digitalRead(inButton2);
    
      if(buttonStatus2 == HIGH) {
        digitalWrite(relayControl2_1, LOW);
      } else {
        digitalWrite(relayControl2_1, HIGH);
      }

      sensorStatus = HIGH;
   }
}
Thanks to the help from @Majenko♦ I was able to fix the issue.
1 - int sensorStatus; should have been set to static int sensorStatus = HIGH; to make the program remember the value of the sensor.
2 - sensorStatus = HIGH; should have been right after digitalWrite(relayControl1_1, HIGH); in the buttonStatus conditional else part to make the program set the sensorStatus back to HIGH correctly.
3 - Unrelated to the question posted, doing the above steps made the program run the motors continuously unless they were stopped by an obstacle from the IR sensor. This was fixed by adding delay(2000); digitalWrite(relayControl1_1, LOW); after the sensorStatus = HIGH; mentioned in the 2nd step.
Source Code after fixing:
const int relayControl1_2 = 12; // relay 1 of 2 (input 2)
const int relayControl2_1 = 11; // relay 2 of 1 (input 3)
const int relayControl2_2 = 10; // relay 2 of 2 (input 4)

const int inButton1 = 9; //input button 1
const int inButton2 = 8; //input button 2

int buttonStatus1 = 0;
int buttonStatus2 = 0;

const int inSensor = 7;

void setup() {
  Serial.begin(9600);
  pinMode(relayControl1_1, OUTPUT);
  pinMode(relayControl1_2, OUTPUT);
  pinMode(relayControl2_1, OUTPUT);
  pinMode(relayControl2_2, OUTPUT);

  pinMode(inButton1, INPUT_PULLUP);
  pinMode(inButton2, INPUT_PULLUP);

  pinMode(inSensor, INPUT_PULLUP);

}

void loop() {

  static int sensorStatus = HIGH;

  if (digitalRead(inSensor) == LOW) {
    sensorStatus = LOW;
  }

  if(sensorStatus == LOW) {
      buttonStatus1 = digitalRead(inButton1);
  
      if(buttonStatus1 == HIGH) {
        digitalWrite(relayControl1_1, LOW);
      } else {
        digitalWrite(relayControl1_1, HIGH);
        sensorStatus = HIGH;
        delay(2000);
        digitalWrite(relayControl1_1, LOW);
      }
    
      buttonStatus2 = digitalRead(inButton2);
    
      if(buttonStatus2 == HIGH) {
        digitalWrite(relayControl2_1, LOW);
      } else {
        digitalWrite(relayControl2_1, HIGH);
        sensorStatus = HIGH;
        delay(2000);
        digitalWrite(relayControl2_1, LOW);
      }
   }
}