Problem with object instance

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

Hi guys,
I have a problem, i’m doing a character that can shoot some fireballs,
i coded it that he can shoot a fireball only when the animation frame reaches the number 5.
The problem is that when I shoot it create not only one fireball, but more than one.
What is the problem? Thank you in advance
This is the code I used:

func fire_attack():
if  Input.is_action_pressed("attack") and is_on_floor() and movimento.x==0 and fire_power_up==true:
	if $AnimatedSprite.get_frame()==5:
		var fireball= preload("res://scenes/magics/fireball.tscn").instance()
:bust_in_silhouette: Reply From: stevepetoskey

Does your animation reset? if so try changing Input.is_action_pressed to Input.is_action_just_pressed
If you did not make it so the animation resets I recommend resetting it in theif $AnimatedSprite.get_frame()==5: statement