How do i fix this to make an item pickup work?look in the comment

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

Extends Area2d

Var stats = PlayeeStats
#Playerstats is an autoload
Onready var animatedSprite = preload (“res://HealEffect.tscn”)
#this was supposed to be a effect for when you use the item but i still dont know how to properly play animations in scripts
Onready var text = $F

the text to say press F to pick up

Func _on_Area2D_body_entered(body):
Text.show()
If Input.is_action_just_pressed(“pickup”)
#pickup is my input “F” so that they can pickup the items by pressing F
queue_free()
stats.health += 1

my prblem is that whenever i press f while in the area nothing happens

Func _on_area2d_body_exited(body):
Text.hide

Pls help idk why it dosent work when i try to pick it up

:bust_in_silhouette: Reply From: njamster

my prblem is that whenever i press f while in the area nothing happens

Because _on_Area2D_body_entered is called once when a body enters the area. So unless you manage to press “F” in precisely that one frame, it will be ignored.

This should work:

extends Area2D

onready var text = $F

func _ready():
	set_process(false)

func _process(delta):
	text.show()
	if Input.is_action_just_pressed("pickup"):
            queue_free()
		stats.health += 1

func _on_Area2D_body_entered(body):
	set_process(true)    

func _on_Area2D_body_exited(body):
	set_process(false)
	text.hide()

but i still dont know how to properly play animations in scripts

Nothing special about it: animatedSprite.play("<AnimationName>")

Also please make sure your code is properly formatted the next time you post here.