limit switches for a motor

I have an egg incubator and when I open the door I want the racks to center them selves and then turn off. so I would have a limit switch in the door to know when its open and one on the motor mechanism to let it know when its at the stop point.

I have tried this code with pull ups on and when the door is opened. making the doorstatus go high it jumps to door open rack centered and it doesn't seem to matter what state the positionzero pin is at low or high.... not sure why

Any ideas?

   if (doorstatus == HIGH)
    {
      (positionzero == BUT5);
     if (positionzero == HIGH)
     {
     digitalWrite(motorpin, LOW);
     lcd.clear();
     lcd.setCursor(0, 2);
     lcd.print("     Door  Open     ");
     lcd.setCursor(0, 3);
     lcd.print(" Centering Rack.... ");
     }
    if (positionzero == LOW)
     {
     digitalWrite(motorpin, HIGH);
     lcd.clear();
     lcd.setCursor(0, 2);
     lcd.print("     Door  Open     ");
     lcd.setCursor(0, 3);
     lcd.print("   Rack  Centered   ");
     
    }
    delay (1000);
   }
    
    if (doorstatus == LOW)
    {
      digitalWrite(motorpin, HIGH);
    }

I did this and it seems to work now haha

   if (doorstatus == HIGH)
    {
     
     if (digitalRead (BUT5) == HIGH)
     {
     digitalWrite(motorpin, LOW);
     lcd.clear();
     lcd.setCursor(0, 2);
     lcd.print("     Door  Open     ");
     lcd.setCursor(0, 3);
     lcd.print(" Centering Rack.... ");
     }
    if (digitalRead (BUT5) == LOW)
     {
     digitalWrite(motorpin, HIGH);
     lcd.clear();
     lcd.setCursor(0, 2);
     lcd.print("     Door  Open     ");
     lcd.setCursor(0, 3);
     lcd.print("   Rack  Centered   ");
     
    }
    delay (1000);
   }
    
    if (doorstatus == LOW)
    {
      digitalWrite(motorpin, HIGH);
    }

See, you were an expert all along.

Read up about state machines for this sort of programming, state transition diagrams are a great aid
to coding such interactions.