motor and slot encoder program issue

Below is a code i adapted from the encoder code example. I have a motor with an ir slot encoder and slotted wheel. I will have the shaft also connected to a string like how a winch is setup.
| __________
| | | _______
—|------| --------||
| |
__|
[ | ]

^ ^ ^
encoder motor winch
& wheel

In the code below i am trying to turn the motor just enough to pull in all the string.
My problem lies in when i run the code it will only start the motor if i give it a little nudge and start a count i need it to start when i call this code inside my final code

 int motor = 8;
 int val; 
 int encoder0PinA = 3;
 int encoder0PinB = 4;
 int encoder0Pos = 0;
 int encoder0PinALast = LOW;
 int n = LOW;

 void setup() { 
   pinMode (motor,OUTPUT);
   pinMode (encoder0PinA,INPUT);
   pinMode (encoder0PinB,INPUT);
   Serial.begin (9600);
   
 } 

 void loop() { 
   n = digitalRead(encoder0PinA);
   if ((encoder0PinALast == LOW) && (n == HIGH)) {
     if (digitalRead(encoder0PinB) == LOW) {
       encoder0Pos--;
     } else {
       encoder0Pos++;
     }
     if(encoder0Pos< 500){
    digitalWrite(motor,HIGH);
     }
     else{
       digitalWrite(motor,LOW);
     }
     Serial.print (encoder0Pos);
     Serial.print ("/");
   } 
   encoder0PinALast = n;
 }

My problem lies in when i run the code it will only start the motor if i give it a little nudge

What kind of motor? How is it connected to the Arduino? How is it powered?

If the encoder is connected to the motor, and the motor is stopped, the encoder never changes position. So, moving the motor only when the encoder changes position does not make sense.

You need to determine the encoder position INDEPENDENTLY from moving the motor.

You need some other way, besides bumping the motor, to tell it to start moving.

The motor is separate from the encoder. The encoder is connecter to 2 different pins to tell direction. The motor is connected to pin 8 with a transistor. I didn't use pwm because i have no need to control speed. I'm only looking for how many counts of the wheel have gone by to tell how many rotations of the motor. I have the motor and encoder setup on a computer power supply separate from the arduino on a breadboard with the ground to the ground of the arduino.

The motor is separate from the encoder.

Not according to your ASCII art.

Anyway, nothing happens in your code until the encoder changes position. According to your artwork, the encoder is coupled to the motor, which makes sense if what you are trying to read is the position of the motor based on encoder pulses.

You need an independent way to tell the motor to start moving, and then you use the encoder information to tell it when to stop.

I am stumped at how to program this. The situation i have is the diagram in my first post is also connected to a servo to tilt the motor and winch to let a string on the winch drop and after some time tilt back and wind up the string. This is triggered by a ping one wire distance sensor. And a potentiometer to adjust the trigger distance. My biggest problem is having the motor on the winch to turn a specific number of times using the encoder. The program as I have posted will only turn the motor if I give the wheel a slight nudge to initiate an encoder pulse. Any guidance would be greatly appreciated dice this is a Halloween project and the holiday is tomarrow