Logic problem with code

I'm creating a project that is a vehicle sensing system that detects the distance of the vehicle and also if its in the right place by the use of buttons.

The problem that i am having is i don't know who to call a function depending of the status of the previous function.

I want pushbuttonsFunction(); to run first and if the 'greenled' is on then distanceFunction(); to run. Finally, if 'led6' is on from distanceFunction(); then servoFunction(); should run.

Below is my code:

#include 

//Distance sensor definition 
#define trigPin A0
#define echoPin A1
#define buzzer A2
#define led 13
#define led2 12
#define led3 11
#define led4 10
#define led5 9
#define led6 8

int sound = 250;

//Pushbuttons definition
int yellowbutton = 2;         // the number of the input pin
int yellowled = 5;       // the number of the output pin

int state = HIGH;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin


int greenbutton = 3;         
int greenled = 4;   

int state1 = HIGH;      
int reading1;           
int previous1 = LOW;                     
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers


//Servo definition
int button = 7; //button pin, connect to ground to move servo
int press = 0;
Servo servo;
boolean toggle = true;

void setup() {
  
//Distance sensor setup
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(buzzer, OUTPUT);

//Pushbutton setup
  pinMode(yellowbutton, INPUT);
  pinMode(yellowled, OUTPUT);

  pinMode(greenbutton, INPUT);
  pinMode(greenled, OUTPUT);  

//Servo setup
  pinMode(button, INPUT); //arduino monitor pin state
  servo.attach(6); //pin for servo control signal
  digitalWrite(7, HIGH); //enable pullups to make pin high
  

}

void loop()
{
  pushbuttonsFunction();

  distanceFunction();
  
  servoFunction();
  
} 



void pushbuttonsFunction()
{
  reading = digitalRead(yellowbutton);


  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH)
      state = LOW;
    else
      state = HIGH;

    time = millis();    
  }

  digitalWrite(yellowled, state);

  previous = reading;


  reading1 = digitalRead(greenbutton);


  if (reading1 == HIGH && previous1 == LOW && millis() - time > debounce) {
    if (state1 == HIGH)
      state1 = LOW;
    else
      state1 = HIGH;

    time = millis();    
  }

  digitalWrite(greenled, state1);

  previous1 = reading1;
}





void distanceFunction()
{
  
  long duration, distance;
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;







  if (distance <= 30) {
    digitalWrite(led, HIGH);
    sound = 250;
}
  else {
    digitalWrite(led,LOW);
  }
  if (distance < 25) {
      digitalWrite(led2, HIGH);
      sound = 260;
}
  else {
      digitalWrite(led2, LOW);
  }
  if (distance < 20) {
      digitalWrite(led3, HIGH);
      sound = 270;
} 
  else {
    digitalWrite(led3, LOW);
  }
  if (distance < 15) {
    digitalWrite(led4, HIGH);
    sound = 280;
}
  else {
    digitalWrite(led4,LOW);
  }
  if (distance < 10) {
    digitalWrite(led5, HIGH);
    sound = 290;
}
  else {
    digitalWrite(led5,LOW);
  }
  if (distance < 5) {
    digitalWrite(led6, HIGH);
    sound = 300;
}
  else {
    digitalWrite(led6,LOW);
  }

  if (distance > 30 || distance <= 0){
    Serial.println("Out of range");
    noTone(buzzer);
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
    tone(buzzer, sound);
   
  }
  delay(500);
}


void servoFunction()
{
   press = digitalRead(button);
  if (press == LOW)
  {
    if(toggle)
    {
      servo.write(9360);
      toggle = !toggle;
    }
    else
    {
      servo.write(20);
      toggle = !toggle;
    }
  }
  delay(500);  //delay for debounce
}

Id be grateful if someone could point me in the right direction of the if statements that will look at a previous function and call the next function to start.

Thanks, Connor.

if the 'greenled' is on then distanceFunction(); to run.

Either create a variable that holds the state of the LED that you want to test and change its state when you change the state of the LED, or slower to execute, read the state of the LED pin and test what is returned.

(deleted)