This isn't working Pls help

Godot v4.4.4

Heya i’m a bit stuck with my attack animation breaking and not playing out all the way when used. and it only seems to happen when my other player animations are in the script.
Heres the code:

#flips sprite
		if direction > 0:
			sprite.flip_h = false
		if direction < 0:
			sprite.flip_h = true
		if direction == 0:"Idle")
		if direction == 1:"Run")
		if direction == -1:"Run")
		if velocity.y != 0:"Jump")
		if Input.is_action_just_pressed("Attack") and sprite.flip_h == true:"SlashLeft")
		if Input.is_action_just_pressed("Attack") and sprite.flip_h == false:"SlashRight")

if you need me to elaborate further on the problem feel free to ask.
cheers if you can help :slightly_smiling_face:

It looks like you’re having trouble with your attack animation not playing fully when your other player animations are in the script.

From what I can see, the issue might be due to the way you’re handling your animation states. In your code, you’re checking for multiple conditions and playing different animations based on those conditions. However, if multiple conditions are true at the same time, it can cause the animation to change mid-play, which might be why your attack animation is not playing fully.

Here are a few suggestions to help you resolve this issue:

  1. Use a state machine: Instead of checking for multiple conditions and playing animations directly, consider using a state machine to manage your animation states. This way, you can ensure that only one animation is playing at a time, and you can handle transitions between states more cleanly.

  2. Use animation priorities: In Godot, you can set priorities for your animations. This way, if multiple animations are trying to play at the same time, the one with the higher priority will take precedence. You can use this to ensure that your attack animation takes priority over your other animations.

  3. Use a separate function for attack animation: Instead of checking for the attack input in your main animation handling code, consider creating a separate function for handling the attack animation. This way, you can isolate the attack animation logic and ensure that it’s not affected by your other animation logic.

Here’s an example of how you could implement a state machine using an enumeration:

enum State {

var current_state = State.IDLE

func _process(delta):
    # Update state based on input and conditions
    if Input.is_action_just_pressed("Attack") and (current_state == State.IDLE or current_state == State.RUN):
        current_state = State.ATTACK
    elif direction!= 0 and velocity.y == 0:
        current_state = State.RUN
    elif velocity.y!= 0:
        current_state = State.JUMP
        current_state = State.IDLE

    # Play animation based on state
    match current_state:
            if direction > 0:
            if sprite.flip_h == true:

Remember to adapt this example to your specific use case, and adjust the state transitions and animation logic as needed.