Enemie error animation please help

Godot Version

4.1.2

I’m having an error that the truth is that I don’t understand the enemy that I made when he dies outside the plant area it plays the death animation but when he dies in the plant area it doesn’t play the death animation and I really don’t understand the error All this happened when I deactivated the hitbox in the death animations. “Plant” is a node that the enemy heads towards and attacks. code:


@export var movement_speed = 65

@onready var planta =  get_tree().get_first_node_in_group("planta")
@onready var sprite = $Sprite2D
@onready var vida = 35
@onready var flash = $hitflash

func _physics_process(_delta):
	if is_instance_valid(planta):
		var direction = global_position.direction_to(planta.global_position)
		velocity = direction*movement_speed
		move_and_slide()
		

		if direction.x > 0:
			sprite.flip_h = false
		
		elif direction.x < 0:
			sprite.flip_h = true
			
	else:
		planta = get_tree().get_first_node_in_group("planta")
		move_and_slide()
	


func _ready():
	$lil.play("move")










func _on_area_2d_area_entered(_area):
	if _area.is_in_group("planta_area"):
		$lil.play("attack")

		
	elif _area.is_in_group("bala"):
		flash.play("hit_flash")
		vida -= 9
		
	if vida <= 0:
		set_physics_process(false)
		$lil.play("ded")
		await get_tree().create_timer(0.8).timeout
		queue_free()









func _on_area_2d_area_exited(_area):
	if _area.is_in_group("planta_area"):
		$lil.play("move")````

You need to show which error is appearing

I’m not sure, but maybe deactivating the hitbox triggers the _on_area_2d_area_exited() function, and the animation changes to "move".

As a side note, you can optimize the sprite flipping by only doing one if-statement:

if direction.x != 0.0:
    sprite.flip_h = direction.x < 0.0

My friend,it’s not an error in itself, it doesn’t give me any errors, but it doesn’t do what I want. I forgot to write this part of the code goes under the $lil.play attack of the entered area

	set_physics_process(false)
	await get_tree().create_timer(10).timeout

How could I fix it? don’t want to activate the hitbox because it was so that the bullets wouldn’t continue colliding towards the enemy

You could try disconnecting the area_exited signal before playing the death animation.

how i can disconnect by code?