Connect IR sensor to L293D motor driver shield (For stopping the car)

I’m using Arduino Mega 2560 along with L293D motor driver shield to build a model of an electric train which the train will from from station1-2 using ir sensor to stop after 5seconds, it starts moving again to station3 and stop for 5s.**(The code works fine)…
But when I add the backward command, the motors don’t move and make noise.
Please help me check this code I would appreciate a lot for helping. Thank you!

#include <AFMotor.h>
int irs = 20;

AF_DCMotor motor1 (1);
AF_DCMotor motor2 (2);
AF_DCMotor motor3 (3);
AF_DCMotor motor4 (4);
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(irs, INPUT);

  motor1.setSpeed(60);
  motor2.setSpeed(60);
  motor3.setSpeed(60);
  motor4.setSpeed(60);

}

void loop() {
  // put your main code here, to run repeatedly:
  moveForward(); // 1-2
  sensor();
  moveForward(); // 2-3
  sensor();
  moveBackward();// Reverse 3-2
  sensor();
  moveBackward();// Reverse 2-1
  sensor();
 
}
//setting variable
void moveForward() {
    motor1.run(FORWARD);
    motor2.run(FORWARD);
    motor3.run(FORWARD);
    motor4.run(FORWARD);
  }
void moveStop() {
  motor1.run(RELEASE); //Stop the train for 5000 ms
  motor2.run(RELEASE);
  motor3.run(RELEASE);
  motor4.run(RELEASE);
}

void moveBackward() {
    motor1.run(BACKWARD);
    motor2.run(BACKWARD);
    motor3.run(BACKWARD);
    motor4.run(BACKWARD);
  
}
void sensor() {
  if (digitalRead(irs) == LOW) {//If ir sensor detects, move forward for 20ms 
    moveForward();              // then come to finally stop for 5000ms
    delay(20);
    moveStop();
    delay(5000);
  }
}