Ultrasonic to Servo Movement

Hello y’all,
I am trying to use an ultrasonic motion sensor to move a servo motor. The motor is going to press a button on something else when it moves. My ultimate goal is for a person to step in front of the sensor and the servo presses the button, then the person moves out from in front of the sensor and the servo presses the same button. I’m trying to use a potentiometer to help adjust the movement of the servo. If you have an idea that would get rid of the pot, I am open. Any suggestions?
Here is my current code:
#include <Servo.h>

#define trigPin 2
#define echoPin 4
#define potPin 2

Servo myservo;
int distance;
int i;

void setup()
{
myservo.attach(9);
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
myservo.write(0);
}

void loop()
{
digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);

{
myservo.write(180);
delay(0);
myservo.write(0);
}
delay(map(analogRead(potPin),0,10000,200,2000));

}

Thank You!

firstly put your code in '#' tags please!

i still cant get you problem finely? do you mean that you have to adjust the servo everytime