Help with sketch

What do i need to change to get the 5 second wait to restart after button 6 goes back high and do nothing is button 5 is pressed?
Im not very good at coding and have just been copy and pasting might be why its not working ?
any help would be great thanx

#include <AccelStepper.h>

// DRV8825 control pins
#define STEP_PIN 8
#define DIR_PIN  9

// Create stepper object (DRIVER = 1 for step/dir driver)
AccelStepper stepper(AccelStepper::DRIVER, STEP_PIN, DIR_PIN);

// Button pins
const int BUTTON1 = 2;
const int BUTTON2 = 3;
const int BUTTON3 = 4;
const int BUTTON4 = 5;
const int BUTTON5 = 6;
const int BUTTON6 = 7;

// Speeds in steps per second
const float FAST_SPEED   = 1000.0;
const float MEDIUM_SPEED = 500.0;
const float CREEP_SPEED  = 100.0;

// State machine
enum State {
  IDLE,
  CW_FAST,
  CW_CREEP,
  WAITING,
  CCW_MEDIUM,
  CCW_CREEP
};

State currentState = IDLE;
unsigned long waitStart = 0;
bool button1Handled = false; // track fresh press for Button 1

void setup() {
  Serial.begin(9600);

  // Initialize stepper
  stepper.setMaxSpeed(2000);         // Adjust max speed as needed
  stepper.setAcceleration(1000);     // Optional for smoother starts/stops

  // Button inputs
  pinMode(BUTTON1, INPUT_PULLUP);
  pinMode(BUTTON2, INPUT_PULLUP);
  pinMode(BUTTON3, INPUT_PULLUP);
  pinMode(BUTTON4, INPUT_PULLUP);
  pinMode(BUTTON5, INPUT_PULLUP);
  pinMode(BUTTON6, INPUT_PULLUP);

  Serial.println("Stepper Ready.");
}

void loop() {
  // Allow stepper to move
  stepper.runSpeed();

  // Handle Button 1 – Restart only on fresh press
  if (digitalRead(BUTTON1) == LOW && !button1Handled) {
    Serial.println("Button 1: Restart CW fast");
    currentState = CW_FAST;
    stepper.setSpeed(FAST_SPEED); // CW direction
    button1Handled = true;
  } else if (digitalRead(BUTTON1) == HIGH) {
    button1Handled = false; // Reset flag when button is released
  }

  switch (currentState) {
    case CW_FAST:
      if (digitalRead(BUTTON2) == LOW) {
        Serial.println("Button 2: Switch to CW creep");
        currentState = CW_CREEP;
        stepper.setSpeed(CREEP_SPEED); // Still CW
        delay(200);
      }
      break;

    case CW_CREEP:
      if (digitalRead(BUTTON3) == LOW) {
        Serial.println("Button 3: Stop, wait 5s, then CCW medium");
        stepper.setSpeed(0);         // Stop
        currentState = WAITING;
        waitStart = millis();        // Start 5-second timer
        delay(200);
      }
      break;

    case WAITING:
      if (millis() - waitStart >= 5000) {
        Serial.println("5 seconds done. Starting CCW medium");
        currentState = CCW_MEDIUM;
        stepper.setSpeed(-MEDIUM_SPEED); // CCW
      }
      break;

    case CCW_MEDIUM:
      if (digitalRead(BUTTON4) == LOW) {
        Serial.println("Button 4: Switch to CCW creep");
        currentState = CCW_CREEP;
        stepper.setSpeed(-CREEP_SPEED);
        delay(200);
      }
      if (digitalRead(BUTTON6) == LOW) {
        Serial.println("Button 6: Interrupt and restart");
        stepper.setSpeed(0);
        currentState = IDLE;
        delay(200);
      }
      break;

    case CCW_CREEP:
      if (digitalRead(BUTTON5) == LOW) {
        Serial.println("Button 5: Stop CCW creep");
        stepper.setSpeed(0);
        currentState = IDLE;
        delay(200);
      }
      if (digitalRead(BUTTON6) == LOW) {
        Serial.println("Button 6: Interrupt and restart");
        stepper.setSpeed(0);
        currentState = IDLE;
        delay(200);
      }
      break;

    case IDLE:
    default:
      // Do nothing
      break;
  }
}

It looks like button 6 does not have a "case" and is dependent on button 4 or button 5.

im making a mini sliding door the buttons are essentially limit switches and button 6 is a safety so it wont time out and close
so button one opens until it hits button 2 then slows down until button 3 stops and waits 5 seconds then initiates a close cycle until button 4 then slows until button 5 then stops button 6 should do nothing if 5 is pressed

This will stop the motor in CCW_CREEP and never get to the next line of code.

stepper.setSpeed(0);

It is trying to get to the destination at 0 steps per ?minute/second? in the calculation the library is doing. (divide or multiply by zero).

it all works it just does not stop the 5 second wait it just stops i can start it all over and it works again until i hit button 6 then just stops

That is what I said in post 4.

yes when button 6 goes low it is NOT supposed to move the stepper it supposed to wait until 6 goes back high then wait the 5 seconds and move but it never does

The sketch will not proceed until the stepper.setspeed reaches its destination, but you have instructed it to make (0) steps per second/minute.

Here is the wokwi.com diagram.json code that I am using to simulate your sketch...

diagram.json for workwi
{
  "version": 1,
  "author": "Anonymous maker",
  "editor": "wokwi",
  "parts": [
    { "type": "wokwi-arduino-nano", "id": "nano", "top": -62.4, "left": -77.3, "attrs": {} },
    {
      "type": "wokwi-stepper-motor",
      "id": "stepper1",
      "top": -230.41,
      "left": -6.18,
      "attrs": { "size": "8", "arrow": "white", "display": "angle" }
    },
    { "type": "wokwi-a4988", "id": "drv1", "top": -148.8, "left": -72, "attrs": {} },
    { "type": "wokwi-gnd", "id": "gnd1", "top": 0, "left": 57, "attrs": {} },
    { "type": "wokwi-dip-switch-8", "id": "sw2", "top": -60.9, "left": 97.5, "attrs": {} },
    { "type": "wokwi-vcc", "id": "vcc1", "top": -191.24, "left": -28.8, "attrs": {} }
  ],
  "connections": [
    [ "gnd1:GND", "nano:GND.1", "black", [ "v-9.6", "h153.6" ] ],
    [ "nano:GND.2", "drv1:GND.1", "black", [ "v-1.88", "h-0.24", "v-70.41" ] ],
    [ "drv1:SLEEP", "drv1:RESET", "black", [ "h-9.6", "v-9.6" ] ],
    [ "drv1:VDD", "drv1:VMOT", "red", [ "h15.68", "v-56.09" ] ],
    [ "drv1:GND.2", "drv1:GND.1", "black", [ "h9.8", "v57.19" ] ],
    [ "drv1:1A", "stepper1:B-", "green", [ "h35.55", "v0.08", "h51" ] ],
    [ "drv1:1B", "stepper1:B+", "green", [ "h28.25", "v0.08", "h48.7" ] ],
    [ "drv1:2A", "stepper1:A-", "green", [ "h0" ] ],
    [ "drv1:2B", "stepper1:A+", "green", [ "h0" ] ],
    [ "sw2:1b", "nano:7", "green", [ "v-9.3", "h-67.2" ] ],
    [ "sw2:2b", "nano:6", "green", [ "v-9.3", "h-144" ] ],
    [ "sw2:3b", "nano:5", "green", [ "v-9.3", "h-144" ] ],
    [ "sw2:4b", "nano:4", "green", [ "v-9.3", "h-115.2" ] ],
    [ "sw2:5b", "nano:3", "green", [ "v-9.3", "h-105.6" ] ],
    [ "sw2:6b", "nano:2", "green", [ "v-9.3", "h-115.2" ] ],
    [ "nano:GND.1", "sw2:1a", "black", [ "v0" ] ],
    [ "sw2:1a", "sw2:2a", "green", [ "v0" ] ],
    [ "sw2:2a", "sw2:3a", "green", [ "v0" ] ],
    [ "sw2:3a", "sw2:4a", "green", [ "v0" ] ],
    [ "sw2:4a", "sw2:5a", "green", [ "v0" ] ],
    [ "sw2:5a", "sw2:6a", "green", [ "v0" ] ],
    [ "vcc1:VCC", "drv1:VMOT", "red", [ "v0" ] ],
    [ "nano:8", "drv1:STEP", "green", [ "v-9.6", "h-57.6", "v-9.6" ] ],
    [ "nano:9", "drv1:DIR", "green", [ "v-9.6", "h-48", "v-9.6" ] ]
  ],
  "dependencies": {}
}