how do i get a momentary switch to act as a latching switch in the sketch?

I am finding my way through the Arduino maze. I have a sketch that works BUT I want the switch to latch when pressed and back again when pressed again. What I want it to do is when the button is pushed for the servo to move to a point and certain pins go high (LEDS) and stay that way until the button is pressed again in which it moves back to its original point. At the moment it works how I want it but the switches dont latch. There are 4 buttons on the sketch.

I have tried several things and they havent worked and ended up in a mess.

I be using ULN2803 chip to switch the LEDS

This is firt time posting here so if you need more info please feel free to ask.

//4 servos with leds

#include <Servo.h> 

// create servo objects to control a servos

Servo myservo0;  
Servo myservo1;
Servo myservo2;
Servo myservo3;

// input pin used to connect the buttons

const int button0 = A0;  
const int button1 = A1;
const int button2 = A2;
const int button3 = A3;

// ouput pin used to connect leds etc

const int led0A = 2;
const int led0B = 4;
const int led1A = 6;
const int led1B = 7;
const int led2A = 8;
const int led2B = 9;
const int led3A = 12;
const int led3B = 13;
const int led0Z = A4;
const int led1Z = A5;
const int led2Z = A6;
const int led3Z = A7;

//buttonstatus

int buttonState0 = 0; 
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;

//configuration inside setup function

void setup() {
  pinMode(button0,INPUT); 
  pinMode(button1,INPUT);
  pinMode(button2,INPUT);
  pinMode(button3,INPUT);

  pinMode (led0A, OUTPUT);
  pinMode (led0B, OUTPUT);
  pinMode (led1A, OUTPUT);
  pinMode (led1B, OUTPUT);
  pinMode (led2A, OUTPUT);
  pinMode (led2B, OUTPUT);
  pinMode (led3A, OUTPUT);
  pinMode (led3B, OUTPUT);
  pinMode (led0Z, OUTPUT);
  pinMode (led1Z, OUTPUT);
  pinMode (led2Z, OUTPUT);
  pinMode (led3Z, OUTPUT);

  // attaches the servo on pin to the servo objects
  
  myservo0.attach(3);  
  myservo1.attach(5);
  myservo2.attach(10);
  myservo3.attach(11);
  
}

void loop() {
  buttonState0 = digitalRead(button0);
  buttonState1 = digitalRead(button1);
  buttonState2 = digitalRead(button2);
  buttonState3 = digitalRead(button3);

  // button 0

  if(buttonState0 == LOW){
    myservo0.write(0);
    digitalWrite (led0A, LOW);
    digitalWrite (led0B, HIGH);
    digitalWrite (led0Z, LOW);
  }
  else if(buttonState0 == HIGH){
    myservo0.write(90);
    digitalWrite (led0A, HIGH);
    digitalWrite (led0B, LOW);
    digitalWrite (led0Z,HIGH); 
  }

  //button 1
  
  if(buttonState1 == LOW){
    myservo1.write(90);
    digitalWrite (led1A, LOW);
    digitalWrite (led1B, HIGH);
    digitalWrite (led1Z, LOW);
  }
  else if(buttonState1 == HIGH){
    myservo1.write(0);
    digitalWrite (led1A, HIGH);
    digitalWrite (led1B, LOW);
    digitalWrite (led1Z,HIGH);
  }

// button 2
  
  if(buttonState2 == LOW){
    myservo2.write(90);
    digitalWrite (led2A, LOW);
    digitalWrite (led2B, HIGH);
    digitalWrite (led2Z, LOW);
  }
  else if(buttonState2 == HIGH){
    myservo2.write(0);
    digitalWrite (led2A, HIGH);
    digitalWrite (led2B, LOW);
    digitalWrite (led2Z,HIGH);
  }

// button 3
  
  if(buttonState3 == LOW){
    myservo3.write(0);
    digitalWrite (led3A, LOW);
    digitalWrite (led3B, HIGH);
    digitalWrite (led3Z, LOW);
  }
  else if(buttonState3 == HIGH){
    myservo3.write(90);
    digitalWrite (led3A, HIGH);
    digitalWrite (led3B, LOW);
    digitalWrite (led3Z,HIGH);
  }
  }

  // end of code

I want the switch to latch when pressed and back again when pressed again.

Take a look at the StateChangeDetection example in the IDE. You want something to happen when a pin becomes LOW rather than when it is LOW

Your code would also benefit from the use of arrays to avoid repetition of code.

Need state to detect button press, need more state to hold toggle state. Something like:

void setup ()
{
  pinMode (button, INPUT_PULLUP) ;
}

bool button_state = true ;  // button assumed up
bool toggle_state = false ;

void loop ()
{
  bool button_up = digitalRead(button) ;
  if (button_up != button_state)  // detect change in button up/down
  {
    button_state = button_up ;
    if (!button_up)   // if button just pressed, act on it
    {
      toggle_state = ! toggle_state ;  // by toggling the state

      // have new state, so update outputs.
      myservo.write(toggle_state ? 0 : 90);  // condition expressions are powerful and concise
      digitalWrite (led1A, toggle_state);
      digitalWrite (led1B, ! toggle_state);
      digitalWrite (led1Z, toggle_state);
    }
  }
}

Switch

Just change a few variable names and you're good to go.