BCE0044: expecting EOF, found '}' PLEASE HELP

I have a coyote that I am trying to get to chase my character this is the chase code that I have:

var moveDirection : Vector3 = target-transform.position;
var distFromPlayer : Vector3 = player.position-transform.position;

var velocity = rigidbody.velocity;
if(moveDirection.magnitude<1){
	currentWaypoint++;	
}
else if(distFromPlayer.magnitude<30){
	velocity = Vector3.zero;
	 target=player.position;
	velocity = (player.position - transform.position).normalized*speed;
	if((player.position-waypoint[currentWaypoint].position).magnitude>50){
	target = waypoint[currentWaypoint].position;
	velocity= moveDirection.normalized*speed;
	}	
}

else{
	velocity= moveDirection.normalized*speed;
	}
}
else{
	if(loop){
	currentWaypoint=0;

That kind of error stems from not having the correct number of close brackets matched to open brackets. Look through all your code (since it’s obvious that this isn’t all of it) and make sure that there are the exact same number of open brackets as there are close brackets. As long as your code is well formatted, it should be obvious.