I'm creating a distance detector with the sonar and lcd, but the print codes of the "if" statements keeps overlaying each other

#include <LiquidCrystal.h>
#include <NewPing.h>
#define TRIGGER_PIN 3
#define ECHO_PIN 4
#define MAX_DISTANCE 200

int rs=8;
int en=9;
int d4=10;
int d5=11;
int d6=12;
int d7=13;
int distance;
int rLed=5;
int yLed=6;
int gLed=7;

NewPing sonar(TRIGGER_PIN,ECHO_PIN,MAX_DISTANCE);
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(rLed, OUTPUT);
  pinMode(yLed, OUTPUT);
  pinMode(gLed, OUTPUT);
  lcd.begin(16,2);
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(30);
  lcd.setCursor(0,0);
  lcd.print("Distance: ");
  lcd.print(sonar.ping_cm());
  lcd.print("cm");
  delay(100);
  
  distance=sonar.ping_cm();
  lcd.setCursor(0,1);
  if (distance>=20 && distance<=150){
    lcd.print("GOOD RANGE!!!");
    digitalWrite(gLed,HIGH);
    digitalWrite(rLed,LOW);
    digitalWrite(yLed,LOW);
    delay(500);
  }
  else if (distance>10 && distance<20){
    lcd.print("CLOSE!!");
    digitalWrite(yLed,HIGH);
    digitalWrite(rLed,LOW);
    digitalWrite(gLed,LOW);
    delay(500);
  }
  else if (distance<=10){
    lcd.print("TOO CLOSE!!!");
    digitalWrite(rLed,HIGH);
    digitalWrite(yLed,LOW);
    digitalWrite(gLed,LOW);
    delay(500);
  }
  else if (distance>150 && distance<180){
    lcd.print("FAR!!");
    digitalWrite(yLed,HIGH);
    digitalWrite(rLed,LOW);
    digitalWrite(gLed,LOW);
    delay(200);
  }
  else if (distance>=180){
    lcd.print("TOO FAR!!!");
    digitalWrite(rLed,HIGH);
    digitalWrite(yLed,LOW);
    digitalWrite(gLed,LOW);
    delay(500);
  }
  else {
    lcd.print("WHERE ART THOU?");
    digitalWrite(rLed,LOW);
    digitalWrite(yLed,LOW);
    digitalWrite(gLed,LOW);
    delay(500);
  }
  delay(500);
}


Clear a line before printing, e.g. by printing 16 spaces; or at least the area that needs updating.

Whenever the text on the LCD has to change, print a blank line immediately before printing the new text.

Welcome to the forum

Printing to the LCD does not remove what was previously printed unless uou print over it, which you are not

You should clear the LCD before printing a new message, write spaces over the previous message before printing the new one or add spaces to the end of each message to write over the remainder of the previous one

  1. Print a line of spaces before your print statement to clear the line
  2. Make all messages equally in length by adding spaces.
  3. do a clear screen more often

Solution 2 is the most simple.