Moving AI away or towards player not working correctly.

What I am trying to do with the script below is to have the AI move towards the player once the player has entered the overlap sphere. But what happens instead is the AI moves away from the player. What is also weird is that if the player’s X position is greater than zero the AI moves to the right only, if the X position is less than zero the AI moves left only.
I’ve tried using Vector3.Lerp, it worked but I’d much rather use a character controller for movements. Anyways, here is the code.

#pragma strict
var health : float;
var armor : float;
var neutral = false;
var vision_Range : int;
var moveScript : AIMove;
var rayLength : float;
var mask : LayerMask;
var targets : Transform = null;
var controller : CharacterController;

function Update(){
var cols : Collider[] = Physics.OverlapSphere(transform.position, vision_Range, 1<<9);
				//AI jumping
	if (Physics.Raycast(transform.position, Vector3.left, rayLength, mask)){
	moveScript.Jump();
	}else if (Physics.Raycast(transform.position, Vector3.right, rayLength, mask)){
	moveScript.Jump();
	}			//AI jumping
	
	for (var col : Collider in cols){
	targets = col.transform;
	}
	if (targets == null){
	controller.Move(Vector3.zero);
	}else{
	controller.Move(targets.position * Time.deltaTime * 4);
	}
}

You have a number of issue here. Let me address the one in your question first. CharacterController.Move() takes a direction not a position in 3D space. To fix your movement problem replace line 27 with

var moveDir = target.position - transform.position;
controller.Move(moveDir.normalized * Time.deltaTime * speed);

Next is the ‘if (tergets == null)’. Unless your intent is to have your AI return to the origin if it does not find the target, remove lines 24 - 26 and line 28. There is no reason to any action if your intent is for the AI to remain in place if a target is not found.

Lines 21 - 23 just cycle through the colliders of any targets and picks the last one in the list (if any). The list is not ordered, so I’m not sure why that code is there. In addition, if something is found in a previous frame and ‘targets’ get sets, and then there is nothing in the current frame, you code would execute on bad data. For now you could do something like:

if (cols == null || cols.Length == 0)
    targets = null;
else
    targets = cols[0].transform;