My "enemy" when it detects the "player" it always moves forward. And what you should do was go to the "player"

Depending on your enemy, there are a few ways you can do this. I will offer you examples using 2D, as you didn't specify if the game was 2D or 3D.

These are 2D enemy chasing player scripts. Add this function to func _process(delta).

full top-down game:

func hostile(time):
	target = get_node("../Player")
	#if target:
	velocity = global_position.direction_to(target.global_position)
	#position of player minus enemy position will give us direction
	dir = target.position - position

	#get angle from direction (Note roation is in radians)  
	get_node("Sprite").rotation = dir.angle()
	move_and_slide(velocity * SPEED * time)

Another version of top-down can be found here.

https://kidscancode.org/godot_recipes/ai/chase/

A platform enemy is a little different. KidsCanCode has this code for collision detection on a platform for an enemy:


func _physics_process(delta):
    velocity.y += gravity * delta
    if not $RayRight.is_colliding():
        dir = -1
    if not $RayLeft.is_colliding():
        dir = 1
    velocity.x = dir * speed
    $AnimatedSprite.flip_h = velocity.x > 0
    velocity = move_and_slide(velocity, Vector2.UP)

This code can easily be manipulated. If the player in in the enemy line of sight, have the velocity.x flip direction, and the sprite(s) to flip.