Smart traffic light project

Delta_G:
It's not about magical placement. Code is like a list of instructions. You put any line of code at the point in that list where you want that command to be done.

People let the millis thing confuse them and I just don't understand it. This is something you know how to do. If you look at the clock and it is 2:05 right now and I say to meet me in 15 minutes you could handle that right? Working with millis is exactly the same except the clock runs in milliseconds instead of minutes and hours. You still take the time now and subtract the time then to find out how long it has been.

Moving the millis line you have around isn't going to help anything. You have to learn to understand how it is working so you can apply the same technique to the other parts of your code that need timing. This will not work until you have got rid of every single line with delay in it.

So I worked on my code for a bit and now its doing what i want, sort of.

int red1 = 7;
int yellow1 = 6;
int green1 = 5;
int red2 = 4;
int yellow2 = 3;
int green2 = 2;

const int trigPin = 12;
const int echoPin = 11;

long duration;
int distance;

unsigned long currentMillis;
unsigned long currentMillis2;
long interval = 5000;
long pause = 3000;

void setup() {
  pinMode(red1, OUTPUT);
  pinMode(yellow1, OUTPUT);
  pinMode(green1, OUTPUT);
  pinMode(red2, OUTPUT);
  pinMode(yellow2, OUTPUT);
  pinMode(green2, OUTPUT);

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT); 

  currentMillis = millis();

}
void loop() {
  
  //set-up to read distance at sensor 1
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2;

  bool carInRange = distance <= 10;
  bool changeLights = (carInRange == true);

    //neutral period
    if(millis() - currentMillis >= pause){
    digitalWrite(red1, HIGH);
    digitalWrite(yellow1, LOW);
    digitalWrite(green1, LOW);
    digitalWrite(red2, HIGH);
    digitalWrite(yellow2, LOW);
    digitalWrite(green2, LOW);
    }

currentMillis2 = millis();
    
    if(millis() - currentMillis2 >= interval){
      if(changeLights){
    digitalWrite(red1, HIGH);
    digitalWrite(yellow1, LOW);
    digitalWrite(green1, LOW);
    digitalWrite(red2, LOW);
    digitalWrite(yellow2, HIGH);
    digitalWrite(green2, LOW);
  } else {
    digitalWrite(red1, HIGH);
    digitalWrite(yellow1, LOW);
    digitalWrite(green1, LOW);
    digitalWrite(red2, LOW);
    digitalWrite(yellow2, LOW);
    digitalWrite(green2, HIGH);
    }
  }
}

So now my issue is that its not going in a loop, i have my interval for my green2 light to be on for 5 seconds then go back to the neutral period (both red lights are on). Any idea how i can fix this?