Need help with segway robot

So I'm trying to make a segway robot with lego type motors, mpu6050, l298n, and a arduino uno. Im certain i have it all wired right. I made a prototype with continuous motion servos and that was to twitchy.
Here is my code i am currently trying to use.

#include <Wire.h>
#include <MPU6050.h>
int16_t ax, ay, az;
int16_t gx, gy, gz;
int val;
MPU6050 mpu;
int a1 = 4;
int a2 = 5;
int b1 = 7;
int b2 = 8;

void setup() {

Wire.begin();
mpu.initialize();
pinMode(a1, OUTPUT);
pinMode(a2, OUTPUT);
pinMode(b1, OUTPUT);
pinMode(b2, OUTPUT);
digitalWrite(a1, HIGH);
digitalWrite(a2, HIGH);
digitalWrite(b1, HIGH);
digitalWrite(b2, HIGH);
Serial.begin(9600);
}

void loop() {

mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
val = map(ay, -15000, 15000, 0, 500);
if (val > 250) {
digitalWrite(a1, HIGH);
digitalWrite(a2, LOW);
digitalWrite(b1, LOW);
digitalWrite(b2, HIGH);
} else {
digitalWrite(a1, LOW);
digitalWrite(a2, HIGH);
digitalWrite(b1, HIGH);
digitalWrite(b2, LOW);
}
analogWrite(3, val);
analogWrite(6, val);
}

Here is my code i am currently trying to use.

Your improperly posted code does something.

You seem to expect us to know what it actually does and how that differs from what you want it to do. That is not a reasonable expectation.