almost finished!

I have my whole code written and it worked great, however when i re assembled it on the base of the robot the servo will go to nine and then it acts like its glitching out and goes all the way to the left. This is the code i used, but i feel like it might be a grounding issue. Any help would be super!

#include <Servo.h>
#include <CompactQik2s9v1.h>
#include <NewSoftSerial.h>

Servo myservo;

#define rxPin 3
#define txPin 4
#define rstPin 5

NewSoftSerial mySerial = NewSoftSerial(rxPin, txPin);
CompactQik2s9v1 motor = CompactQik2s9v1(&mySerial,rstPin);

void setup()
{
mySerial.begin(9600);
motor.begin();
motor.stopBothMotors();
myservo.attach(6);
myservo.write(90);
}

void loop()
{
motor.motor1Forward(100);
motor.motor0Forward(100);
delay(2000);
int object = analogRead(0);
if ( object >= 170 )
{
motor.stopBothMotors();
delay(2000);
myservo.write(0);
delay(2000);
int left = analogRead(0);
delay(2000);
myservo.write(180);
delay(2000);
int right = analogRead(0);
if ( left > right )
{
motor.motor1Reverse(100);
motor.motor0Forward(100);
delay(1000);
myservo.write(90);
}
else
{
motor.motor0Reverse(100);
motor.motor1Forward(100);
delay(1000);
myservo.write(90);
}
}
else
{
return;
}
}

When you post code, could you please use the "#" button on the editor toolbar?

Maybe some indentation would help too.

This is the code i used, but i feel like it might be a grounding issue

Code doesn't show wiring, so grounding issues are moot.

the servo will go to nine

I wonder what this means.

else
 {
   return;

..just calls "loop" again. Why bother?

I have my whole code written and it worked great, however when i re assembled it on the base of the robot the servo will go to nine and then it acts like its glitching out and goes all the way to the left. This is the code i used, but i feel like it might be a grounding issue. Any help would be super!

If the only thing between working and not working was electrical reassembly, then that is where you need to look for a problem. When servos get bad signals they will travel to to their end stops.