Servo.attach conflicts with other code

I am writing code to control 2 servos and 1 DC motor by using 3 separate joysticks. I am using a L298N H-bridge to control speed and direction of the DC motor. Whenever I comment the “servo.attach” out, I receive speed and direction control of the DC motor. Whenever it is un-commented (i.e. put into the code) I only receive direction control and the speed is full throttle or nothing. Any and all help would be greatly appreciated.

// Arduino code for the entire system
#include <Servo.h> 

Servo rightservo;  // identifies right servo 
Servo leftservo;   // identifies left servo

void setup()
{

int leftjoystick = A3; //attaches variable "leftjoystick" to arduino analog input pin A3
int rightjoystick = A4; //attaches variable "rightjoystick" to arduino analog input pin A4
int boomjoystick = A1;  //attaches variable "boomjoystick" to arduino analog input pin A1
int motorinput1Pin = 12; // H-bridge input (coming from digital pin 12 on arduino)
int motorinput2Pin = 13; // H-bridge input (coming from digital pin 13 on arduino)
int enablePin = 10; // H-bridge speed control pin (by pwm - coming from digital pin 10 on arduino)
int aread;
int valright;    // variable to read the value from the analog pin for the right joystick
int valleft;    // variable to read the value from the analog pin for the left joystick



//defines all output pins as outputs
//pinMode(motorinput1pin, OUTPUT); //sets h-bridge input for motor input 1 on arduino digital pin 12
//pinMode(motorinput2pin, OUTPUT); //sets h-bridge input for motor input 2 on arduino didgital pin 13
//pinMode(enablepin, OUTPUT); //sets h-bridge pwm receiver (enable A) on arduino pwm pin 10
  
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);

}


void loop() 
{
// intializing variables for later use
int leftjoystick = A3; //attaches variable "leftjoystick" to arduino analog input pin A3
int rightjoystick = A4; //attaches variable "rightjoystick" to arduino analog input pin A4
int boomjoystick = A1;  //attaches variable "boomjoystick" to arduino analog input pin A1
int motorinput1Pin = 12; // H-bridge input (coming from digital pin 12 on arduino)
int motorinput2Pin = 13; // H-bridge input (coming from digital pin 13 on arduino)
int enablePin = 10; // H-bridge speed control pin (by pwm - coming from digital pin 10 on arduino)
int aread;
int valright;    // variable to read the value from the analog pin for the right joystick
int valleft;    // variable to read the value from the analog pin for the left joystick


aread = analogRead(A1);

if (aread > 512)
{
  int motorinput1Pin = 12; // H-bridge input (coming from digital pin 12 on arduino)
int motorinput2Pin = 13; // H-bridge input (coming from digital pin 13 on arduino)
  int enablepin = 10;
aread = map(aread,512,1023,0,255);
analogWrite(enablepin,aread);
digitalWrite(motorinput1Pin,LOW);
digitalWrite(motorinput2Pin,HIGH);
delay(10);
}

else if (aread < 510)
{
int motorinput1Pin = 12; // H-bridge input (coming from digital pin 12 on arduino)
int motorinput2Pin = 13; // H-bridge input (coming from digital pin 13 on arduino)
int enablepin = 10;

  aread = map(aread,510,0,0,255);
  analogWrite(enablepin,aread);
  digitalWrite(motorinput1Pin,HIGH);
  digitalWrite(motorinput2Pin,LOW);
  delay(10);
}

else
{
  int enablepin = 10;
 analogWrite(enablepin,0);
}


Serial.println(aread);
  delay(1);
  
  //attach servos to output PWM pins
  //rightservo.attach(3);  // attaching right servo to the analog pin of the right joystick
  //leftservo.attach(9); // attaching left servo to the analog pin of the left joystick
  
  //right joystick code
  valright = analogRead(rightjoystick); // reads the value of the right joystick input at pin A4 (value between 0 and 1023) 

  valright = map(valright, 0, 1023, 0, 179); // scales it to use it with the servo (value between 0 and 180) 

  rightservo.write(valright);  // sets the servo position according to the scaled value 

  delay(15); 

  
  //left joystick code
  valleft = analogRead(leftjoystick); // reads the value of the left joystick input at pin A3 (value between 0 and 1023) 

  valleft = map(valleft, 0, 1023, 0, 179); // scales it to use it with the servo (value between 0 and 180) 

  leftservo.write(valleft); // sets the servo position according to the scaled value 

  delay(15);


}

The reference page for the Servo library (http://arduino.cc/en/reference/servo) explicitly states that PWM on pins 9 and 10 cannot be used if the Servo library is active. In your code you try to use PWM on pin 10 to control the motor's speed.

Tks, now it's working!!!!