lcd 16x2 scroll text [solved]

hello guys, i’m working on my aquarium automation project. and one of the things i had to work on is scrolling text on my lcd 16x2.
i had some problem implementing this. and i realized many others too.
So i decided to share the function i’ve made in order to achive this:

// lcdWidth is declared in globals. this is optional, can you can just replace the varible by 16 on the fucntion
const int lcdWidth = 16;

void lcdPrint(int line, String text){
  // if the text fit the lcd, no need for scrolling, just print the text on the indicated line
  if(text.length() < lcdWidth) {
    lcd.setCursor(0, line);
    lcd.print(text);
  }
  //  but if the text is bigger, than scroll left, than stop, and return text to original position
  else{
    for(int i = 0; i <= (texto.length() - lcdWidth); i++){
      lcd.setCursor(0, line);
      lcd.print(text.substring(i,i+16));
      delay(500);
    }
    delay(1000);
    lcd.setCursor(0, line);
    lcd.print(text);
  }
}

This line

lcd.print(text.substring(i,i+16));

kind of defeats the purpose of

const int lcdWidth = 16;

does it?

Thanks for this update.
Didn't notice it at first.