Rotary encoder menu system

Here is the button press code that works and as far as far as I can see is the same as I'm using in my main program. Only the conditions of what happens when the button is pressed is differnt.

// Push button variables
const byte buttonPin = 4; // Arduino pin the push button is connected to.
byte previousButtonState = HIGH;  // Assume switch open because of pull-up resistor.
byte currentButtonState; // Will be populated by reading button pin satae.
const unsigned long debounceTime = 10;  // Milliseconds of debounce.
unsigned long buttonPressTime;  // Time since button last changed state. Used to differentialte button bounce vs. intentional press.
boolean buttonPressed = 0; // A flag variable to identify button presses. Returned from button debounce code. 

void setup() {
     pinMode (buttonPin, INPUT_PULLUP); // Set button pin as input.
Serial.begin(9600); // Begin Serial monitor.
}

void loop() {
  
  // Button press code with debounce.
  currentButtonState = digitalRead (buttonPin); 
  if (currentButtonState != previousButtonState){
    if (millis () - buttonPressTime >= debounceTime){ // debounce
      buttonPressTime = millis ();  // when we closed the switch 
      previousButtonState = currentButtonState;  // remember for next time 
      if (currentButtonState == LOW){ // When debounce criteria are met and button is still pressed.
        buttonPressed = 1; // Set button flag to 1.
        Serial.println("Button Pressed");
      }
      else { // When debounce criteria are not met because boutton is not pressed or it is bouncing.
        buttonPressed = 0;  // Set button flag to 0.
      }
    }
  }

}