Still cant get my head round this

This sketch works OK apart from the fact that the input on 2 and 3 will work both or either or servo. I would like one button input to control its own servo. Then add more servos with their own buttons. Any help would be very nice thanks.

#include <Servo.h>

Servo myservo; // create servo object to control a servo
Servo myservo1; // a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position
int pos1=0;
int buttonPin = 2; // The button will be on Pin2
int buttonPin1 =3;
void setup()
{ myservo1. attach(8);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(pos, OUTPUT);
pinMode(pos1,OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(buttonPin1,INPUT);
digitalWrite(buttonPin1,LOW);
digitalWrite (buttonPin, LOW);
}

void loop()

{
void();
{
if (digitalRead(buttonPin) == LOW)

for(pos = 0; pos < 30; pos += 30) // goes from 0 degrees to 30 degrees
{ // in steps of degree
myservo.write(pos); // tell servo to go to position in variable 'pos'

}
if (digitalRead(buttonPin) == HIGH)

for(pos = 30; pos>=30; pos-=30) // goes from 30 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay (4000); // waits 4000ms and returns to home position.
}
}
void();

{

if (digitalRead(buttonPin1) == LOW)

for(pos1 = 0; pos1 < 30; pos1 += 30) // goes from 0 degrees to 30 degrees
{ // in steps of degree
myservo1.write(pos1); // tell servo to go to position in variable 'pos'

}
if (digitalRead(buttonPin1) == HIGH)

for(pos1 = 30; pos1>=30; pos1-=30) // goes from 30 degrees to 0 degrees
{
myservo1.write(pos1); // tell servo to go to position in variable 'pos'
delay (4000); // waits 4000ms and returns to home position.
}
}
}

See Demonstration code for several things at the same time - Project Guidance - Arduino Forum

You need to get rid of the for loops and the delays.

Mark

As Mark said, read and understand that link.

The way you are using the loops and delay is going to cause a variety of undesirable things, probably including the one you're dealing with now.

Also:

remove the void(); calls. Why are they there?!

The "right way" to do buttons is to set the pinMode to INPUT_PULLUP, and then connect the other side of the switch to ground, so when you connect the switch, the line goes low. I'm not sure if the way you're doing it will work correctly when you release the switch, unless you have pulldowns on the lines going to the arduino to keep them from floating.