Help! System goes crazy when I combined two codings.

Hello there, I am making a project for smart parking system where I have to use LDR and for my parking space I also have a boom gate. So for the boom gate I used ultrasonic sensor where if it detects a car, then the servo motor will move. These two codings worked fine when they are separate but when I combined them it just goes crazy, please anyone help point out my mistake? Because I really have no idea

Combined coding

#include <Servo.h>
Servo myservo,myservo2;

#define trigPin 13
#define echoPin 12
#define trigPin2 10
#define echoPin2 9

#include <Wire.h>
#include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library
LiquidCrystal_I2C  lcd(0x3F,2,1,0,4,5,6,7,3,POSITIVE);

//pins used for Light Dependent Resistor (ldr)
const int ldrPin[] = {A15,A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14};
//pins used for Light Emitting Diode (LED)
const int ledPin[] = {51,2,3,4,5,6,7,8,9,10,11,12,13,22,24,26};

int ldrStatus[] = {15,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14}; //used to store readings from LDR

void setup() {

  Serial.begin(9600);
  
  lcd.begin (16,2);  // initialize the lcd

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);
 
  myservo.attach(11);
  myservo2.attach(8);
  
  //declare LED as output
  for(int n=0; n<15 ; n++)
  {
    pinMode(ledPin[n],OUTPUT); 
  }
}

void loop() {

  int slot[15];
  
  for (int n = 1; n<16 ; n++) {
  ldrStatus[n] = analogRead(ldrPin[n]);
  ldrStatus[n] = analogRead(ldrPin[n]);

    //Availability of parking slots
    if (ldrStatus[n] >=200) {
    digitalWrite(ledPin[n], HIGH); //turn LED on
   
    Serial.print("Slot ");
    Serial.print(n);
    Serial.println(" available");

    slot[n] = 1;}
   
    else {
    digitalWrite(ledPin[n], LOW);

    Serial.print("Slot ");
    Serial.print(n);
    Serial.println(" unavailable");
           
    slot[n] = 0;}
  }

    int ParkingAvailable = 0;
    for (int i = 1; i <16 ; i++){
    ParkingAvailable = ParkingAvailable + slot[i];
  }

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Space Available:");
  lcd.setCursor(0,1);
  lcd.print(ParkingAvailable);
  Serial.println(ParkingAvailable);

  long duration, distance,pos=0,duration2, distance2,pos2=0,i;
  digitalWrite(trigPin, LOW);  
  delayMicroseconds(2); 
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
   Serial.print(distance);
   Serial.println(" cm");
  if(distance<25)
  {
    myservo.write(90);
    delay(1000);
  }
  else{
    myservo.write(0);
  }
    
  delay(500);

  digitalWrite(trigPin2, LOW);  
  delayMicroseconds(2); 
  digitalWrite(trigPin2, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin2, LOW);
  duration2 = pulseIn(echoPin2, HIGH);
  distance2 = (duration2/2) / 29.1;
   Serial.print("Distance 2 ");
   Serial.print(distance2);
   Serial.println(" cm");
  if(distance2<25)
  {
    myservo2.write(90);
    delay(1000);
  }
  else{
    myservo2.write(0);
  }
}

LDR coding

#include <Wire.h>
#include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library
LiquidCrystal_I2C  lcd(0x3F,2,1,0,4,5,6,7,3,POSITIVE);

//pins used for Light Dependent Resistor (ldr)
const int ldrPin[] = {A15,A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14};
//pins used for Light Emitting Diode (LED)
const int ledPin[] = {51,2,3,4,5,6,7,8,9,10,11,12,13,22,24,26};

int ldrStatus[] = {15,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14}; //used to store readings from LDR

void setup() {

  Serial.begin(9600);
  
  lcd.begin (16,2);  // initialize the lcd
  
  //declare LED as output
  for(int n=0; n<15 ; n++)
  {
    pinMode(ledPin[n],OUTPUT); 
  }
}

void loop() {

  int slot[15];
  
  for (byte n = 1; n<16 ; n++) {
  ldrStatus[n] = analogRead(ldrPin[n]);
  ldrStatus[n] = analogRead(ldrPin[n]);

    //Availability of parking slots
    if (ldrStatus[n] >=200) {
    digitalWrite(ledPin[n], HIGH); //turn LED on
   
    Serial.print("Slot ");
    Serial.print(n);
    Serial.println(" available");

    slot[n] = 1;}
   
    else {
    digitalWrite(ledPin[n], LOW);

    Serial.print("Slot ");
    Serial.print(n);
    Serial.println(" unavailable");
           
    slot[n] = 0;}
  }
  
    int ParkingAvailable = 0;
    for (int i = 1; i <16 ; i++){
        ParkingAvailable = ParkingAvailable + slot[i];
    }
    
  
  
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Space Available:");
  lcd.setCursor(0,1);
  lcd.print(ParkingAvailable);
  //Serial.println(ParkingAvailable);
 delay(1000);
 
 }

Servo and Ultrasonic

long duration, distance,pos=0,duration2, distance2,pos2=0,i;
  digitalWrite(trigPin, LOW);  
  delayMicroseconds(2); 
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
   Serial.print(distance);
   Serial.println(" cm");
  if(distance<25)
  {
    myservo.write(90);
    delay(1000);
  }
  else{
    myservo.write(0);
  }
    
  delay(500);

  digitalWrite(trigPin2, LOW);  
  delayMicroseconds(2); 
  digitalWrite(trigPin2, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin2, LOW);
  duration2 = pulseIn(echoPin2, HIGH);
  distance2 = (duration2/2) / 29.1;
   Serial.print("Distance 2 ");
   Serial.print(distance2);
   Serial.println(" cm");
  if(distance2<25)
  {
    myservo2.write(90);
    delay(1000);
  }
  else{
    myservo2.write(0);
  }
}
#define trigPin 13
#define echoPin 12
#define trigPin2 10
#define echoPin2 9
const int ledPin[] = {51, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 22, 24, 26};

What do you have connected to pins 9, 10, 12 and 13 ?

  int slot[15];
 
  for (int n = 1; n<16 ; n++) {

I thought we'd already discussed this one on another thread?

Why is ldrStatus initialized?

I'll ask the obvious: This is running on a Mega, yes?

Looks like you are using the same pins for different functions.

Makes me wonder how you decided to wire it up?

A wiring diagram might help someone decide which pins are the best to change. Also, working out exactly which wires should go where in sufficient detail to explain it to someone else might help you work out the answer for yourself.