Including "my.enemy = NULL;" is what I was missing.

This code works perfectly smoothly tongue

Code:
function find_enemy()
{
	my.enemy = NULL;
	//////////
	ENTITY* Entenemy;
	var next_target;
	//////////
	for(you=ent_next(NULL); you!=NULL; you=ent_next(you))
	{
		if ((you != my) && (you.team != my.team) && (you.health>0))
		{
			if(my.enemy == NULL)
			{  
				my.enemy = you;
				Entenemy = my.enemy;
				next_target = vec_dist(my.x, you.x);
			}
			else
			{
				if(vec_dist(my.x, you.x) < next_target)
				{
					my.enemy = you;
					Entenemy= my.enemy;
					next_target = vec_dist(my.x, you.x);
				}
			}
		}
	}
}




Thank you!