Why does the enemy only move to the left?

Godot Version 4.2.1.stable

Question

The enemy only moves to the left even though the player is on the right

Enemy script:

extends CharacterBody2D

var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")

var chase = false
var speed = 100
var player_in_attack_area = false
var player_on_scene = true
var damage = 25

@onready var player = $"../../Player/Player"
@onready var attackArea = $AttackArea/CollisionShape2D
@onready var animation = $AnimatedSprite2D

func take_damage():
	$".".queue_free()

func attack():
	animation.play("Attack")
	#player_on_scene = false
	player.take_damage(damage)

func _physics_process(delta):
	if not is_on_floor():
		velocity.y += gravity * delta
	#if player_on_scene:
	
	var direction = (player.position - self.position).normalized()
	
	if chase == true:
		velocity.x = direction.x * speed
		animation.play("Walk")
	else:
		velocity.x = 0
		animation.play("Idle")
	
	move_and_slide()

func _on_player_detector_body_entered(body):
	if body.is_in_group("Player"):
		chase = true

func _on_player_detector_body_exited(body):
	if body.is_in_group("Player"):
		chase = false
		print(chase)


func _on_attack_area_body_entered(body):
	if body.is_in_group("Player"):
		player_in_attack_area = true
		await get_tree().create_timer(2).timeout
		if player_in_attack_area == true:
			attack()

func _on_attack_area_body_exited(body):
	if body.is_in_group("Player"):
		player_in_attack_area = false

You are using local position relative to the node parent instead of global_position relative to the world.