Control DC Motor with H-Bridge Lagging and Bouncing

I am trying to control a 12V DC motor with potentiometer and a switch.

What it should be:
The potentiometer controls the speed, and the switch slows down the motor a little bit if pressed down.

What it actually be:
The potentiometer part is completely working, and the speed is controlled by PWM from Pin 3, Pin 5. When the switch is pressed down, the motor slows down immediately, but when I release the button, the speed of the motor bounces between fast and slow a few times. And after about 2 seconds of delay, the motor return to high speed.

Even if i use button debounce codes, it still happens. So what is the problem in here?

I did not use pull up resister on button pin.

const int buttonPin = 8;    // switch input
const int motor1Pin = 3;    // H-bridge leg 1 (pin 3, 1A)
const int motor2Pin = 5 ;    // H-bridge leg 2 (pin 5, 2A)

int sensorPin = A0;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor
int motorSpeed=0;
int buttonState=0;



void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(motor1Pin, OUTPUT);
  pinMode(motor2Pin, OUTPUT);
}

void loop() {
   int buttonState= digitalRead(buttonPin);
  sensorValue = analogRead(sensorPin);
  motorSpeed =  sensorValue/4;
  
  if(buttonState==HIGH){
    motorSpeed = motorSpeed-100;
  }
  
  if(motorSpeed<10) motorSpeed=0;
      analogWrite(motor1Pin, motorSpeed);   
      analogWrite(motor2Pin, 0);  
  
    
}

You are sensing when the button [u]is[/u] pressed rather than when it [u]becomes[/u] pressed. The loop() function repeats thousands of time per second so you are subtracting 100 from motorSpeed thousands of times per second. No wonder the motor speed does not vary as you expect.

Look at the StateChangeDetection example in the IDE to see how to detect when the button becomes pressed.

I did not use pull up resister on button pin.

You don't say how it is wired either but why no pullup or pulldown resistor ?