How to make a gameobject return to original position (Mathf.PingPong)

I have a script which has an ‘enemy’ PingPong backwards and forward, but follow the player once they get in range. Once the player is out of range I want them to return to their original position but they just appear there rather than moving back towards the original position. Any help?

var target: Transform;
var speed= 2;
var minDistance = 1;
var range;
var myHealth: EnemyScript;
var originalPosition: Vector2;

function Start() {
	myHealth = GetComponent(EnemyScript);
};

function Update () { 

	if(myHealth.enemyHealth == 0){
		Destroy(this);
	};

	range = Vector2.Distance(transform.position,target.position);
	
	if (range < minDistance) {
		move();
		
	}else{
		idleMove();
	};
};
     
    

function move(){
	transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
	if (range > minDistance) {
		transform.position = Vector2.MoveTowards(transform.position,originalPosition, speed * Time.deltaTime);
		};
};

function idleMove(){
	transform.position = Vector2(Mathf.PingPong(Time.time*1, originalPosition.x+1), transform.position.y);
	
};

This answer may be of help.

How to return an object back to it's original position when the player steps off it? - Questions & Answers - Unity Discussions

You can also try lerping or use a coroutine and have it wait every .5 seconds before moving you back a little bit at a time.

How to Lerp like a pro | Chico Unity3D

Coroutines and Lerp - how to make them friends? - Questions & Answers - Unity Discussions