AnimeSprite only runs in an Area2d and only when a Player presses a key.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By David_sun

Hello
I’m trying to get a “player” to open a chest when he presses a key, but only when the player is in a specific area, but it doesn’t work.
Any ideas?
Thank you.

extends Area2D

func _on_chestarea_body_entered(body):
if “player” in body.name:
if Input.is_action_pressed(“ui_focus_next”):
$AnimatedSprite.play(“open”)

func _on_chestarea_body_exited(body):
if “player” in body.name:
if Input.is_action_pressed(“ui_focus_next”):
$AnimatedSprite.play(“close”)