Servo won't turn when Ultrasonic senses it, not sure where I have the problem

So I’m writing code for a servo to turn when an ultrasonic senses it, I checked all my connections and stuff. I have a Miuzei MST8 micro servo and a standard HC-SR04 ultrasonic. What I’m thinking is that the servo move command is the wrong one, as there are other commands to control a servo. Here is the code:

#include<Servo.h>
Servo servo;
int const trigPin = 6;
int const echoPin = 5;
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servo.attach(3);
}
void loop()
{ int duration, distance;
digitalWrite(trigPin, HIGH);
delay(1);
digitalWrite(trigPin, LOW);
// Measure the pulse input in echo pin
duration = pulseIn(echoPin, HIGH);
// Distance is half the duration devided by 29.1 (from datasheet)
distance = (duration/2) / 29.1;
// if distance less than 0.5 meter and more than 0 (0 or less means over range)
if (distance <= 50 && distance >= 0) {
servo.write(50);
delay(3000);
} else {

servo.write(160);
}
// Waiting 60 ms won’t hurt anyone
delay(60);
}

@thetalkingjeff

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.

As it stands, you have no way of knowing if the sensor is working or what "distance" actually is. So first thing is to do a serial print of "distance", I'd say.

and in this part of the code

if (distance <= 50 && distance >= 0) {
   servo.write(50);
    delay(3000);
} else {
   
   servo.write(160);
}

add a few serial prints such as:

if (distance <= 50 && distance >= 0) {
Serial.println( "in range" );   
servo.write(50);
    delay(60);
} else {
   
   servo.write(160);
Serial.println( "out of range" );
}

and change that delay of 3gobzillion to something more reasonable; like 60mSec. Remember if the thingy is waiting 3gobzillion seconds, then nothing else will be happening. If the ranges of servo movement are small, like in 1 degree increments use shorter wait times. More time waiting, less time reading the sensor.

Oh and serial print the distance. Let us know the results. And to be really helpful post your well formatted code in code tags.

Remind us, how many zeroes is a gobzillion?