I have looked for many tutorials but i am unable to find one thats right for what i need;
The turret needs to oscillate left and right and then target the player once it has come in the its field of view and once the player has evaded the turret and remained out of sight for (set amount of time) the turret returns to oscillating left and right.
hope this was explained well.
something like the below picture should work. basically at a regular interval it rotates the turret in the direction dependent on the switch. once the turret reaches a certain rotation (limit) it sets a variable so the next time the script is called it will go in the other direction. the gate near the beginning also gets set to closed when the target is seen which stops the rotation. this type of thing could also be done with a timeline which may be a bit more performant but is also slightly more complex