if statement not working correctly with keyinput

okey sorry for my bit messy code but here it is

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class Movement1 : MonoBehaviour
{

    public float speedF = 5;
    public float speedFF = 1.8F;
    public float speedB = 1.8F;
    public float TurnSpeed = 200;
    public float JumpSpeed = 10;
    public float i;
    public bool runF;
    public bool runB;
    public bool fall;
    public bool MayJump;
    public bool startedCounting;
    public bool teleported;
    public bool Jump;
    public bool death;
    public Transform Player;
    public Rigidbody PlayerRagdoll;
    public Animator anim;
    public int CollisionCount = 0;
    public Slider slider;
    public AudioSource walksound;
    private Rigidbody rb;
    

    // Use this for initialization
    void Start()
    {
        rb = GetComponent<Rigidbody>();
        startedCounting = false;
        death = false;
        slider = Slider.FindObjectOfType<Slider>();
        AudioSource walksound = GetComponent<AudioSource>();
    }

    void Update()
    {
        if (Input.GetKeyUp(KeyCode.UpArrow) || Input.GetKey(KeyCode.W))
        {
            walksound.Stop();
        }
        if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKey(KeyCode.W) && !walksound.isPlaying)
        {
            walksound.Play();
            walksound.loop = true;
        }
        
        //if moving set run true
        if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W) && runB != true)
        {
            runF = true;
        }
        else
        {
            runF = false;
        }
        if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S) && runF != true)
        {
            runB = true;
        }
        else
        {
            runB = false;
        }


        // if running play run animation
        if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W) && runB != true && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("run") && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("fall"))
        {
            anim.Play("run", 0, 0f);
            
        }
        if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S) && runF != true && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("back") && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("fall"))
        {
            anim.Play("back", 0, 0f);
        }
        if (Input.GetKey(KeyCode.Space) && MayJump == true)
        {
            Jump = true;
        }
        else
        {
            if(CollisionCount != 0)
            {
                Jump = false;
            }           
        }
        slider.value -= Time.deltaTime;
        // if not running play idle animation
        if (Input.GetKeyUp(KeyCode.UpArrow) || Input.GetKeyUp(KeyCode.DownArrow) || Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.S) && runB != true && runF != true)
        {
            anim.Play("idle", 0, 0f);
        }
        if (fall == false)
        {
            anim.Play("idle", 0, 0f);
            fall = true;
        }

        if(CollisionCount == 0)
        {
            StartCoroutine("WaitSeconds");
        }
        else
        {
            startedCounting = false;
        }
        //if no collsion play falling animation
        if (CollisionCount == 0 && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("fall") && startedCounting == true)
        {
            anim.Play("fall", 0, 0f);
        }
        if(CollisionCount > 0)
        {
            if (this.anim.GetCurrentAnimatorStateInfo(0).IsName("fall"))
            {
                fall = false;
            }
        }    
        if(GameObject.Find("Stick_Figure_T-pose ragdoll(Clone)"))
        {
            Destroy(gameObject);
        }
        if(slider.value == 0)
        {
            MayJump = false;
        }
        else
        {
            MayJump = true;
        }
    }

please try to ignore everything that doesn’t have to do with animations.
so my problem is that if I run with w a s d i run perfectly fine but when i try and run with the arrow keys my animation starts every frame as if

!this.anim.GetCurrentAnimatorStateInfo(0).IsName("run")

doesn’t exist.

but i also put some sound in the walking called walking sound
but if i walk with w a s d the sound starts every frame as if

!walksound.isPlaying

doesn’t exist
but when i run with the arrow keys the sound works perfectly and stops like it should.
Now the strange thing is that I used || in every if statement that asks input like

if (Input.GetKeyUp(KeyCode.UpArrow) || Input.GetKey(KeyCode.W))
{

}

so I have no clue why my code doesn’t work properly.

The first two if statements in your Update() statement are incorrect.

Try the modified Update() function below.

void Update()
{
    bool upKeyReleased = false;
    bool downKeyReleased = false;
    bool leftKeyReleased = false;  // not currently used
    bool rightKeyReleased = false; // not currently used
    bool upKeyPressed = false;
    bool downKeyPressed = false;
    bool leftKeyPressed = false;   // not currently used
    bool rightKeyPressed = false;  // not currently used
    bool jumpKeyPressed = false;


    if (Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.UpArrow))
    {
        upKeyReleased = true;
    }
    else if (Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.DownArrow))
    {
        downKeyReleased = true;
    }
    else if (Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.LeftArrow))
    {
        leftKeyReleased = true;
    }
    else if (Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.RightArrow))
    {
        rightKeyReleased = true;
    }
    else if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
    {
        upKeyPressed = true;
    }
    else if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
    {
        downKeyPressed = true;
    }
    else if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
    {
        leftKeyPressed = true;
    }
    else if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
    {
        rightKeyPressed = true;
    }

    if (upKeyReleased)
    {
        walksound.Stop();
    }
    else if (upKeyPressed && (!walksound.isPlaying))
    {
        walksound.Play();
        walksound.loop = true;
    }

    //if moving set run true
    if (upKeyPressed && (!runB))
    {
        runF = true;
    }
    else
    {
        runF = false;
    }

    if (downKeyPressed && (!runF))
    {
        runB = true;
    }
    else
    {
        runB = false;
    }


    // if not running running foreward animation and not falling
    if (upKeyPressed && !runB && !fall && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("run") && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("fall"))
    {
        anim.Play("run", 0, 0f);
    }

    // if not running running backward animation and not falling
    if (upKeyPressed && !runF && !fall && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("back") && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("fall"))
    {
        anim.Play("back", 0, 0f);
    }

    if (jumpKeyPressed && MayJump == true)
    {
        Jump = true;
    }
    else
    {
        if(CollisionCount != 0)
        {
            Jump = false;
        }           
    }

    slider.value -= Time.deltaTime;
    // if not running play idle animation
    if ((upKeyReleased || downKeyReleased) && (!runB) && (!runF))
    {
        anim.Play("idle", 0, 0f);
    }

    if (!fall)
    {
        anim.Play("idle", 0, 0f);
        fall = true;
    }

    if(CollisionCount == 0)
    {
        StartCoroutine("WaitSeconds");
    }
    else
    {
        startedCounting = false;
    }

    //if no collsion play falling animation
    if (CollisionCount == 0 && !this.anim.GetCurrentAnimatorStateInfo(0).IsName("fall") && startedCounting == true)
    {
        anim.Play("fall", 0, 0f);
    }

    if(CollisionCount > 0)
    {
        if (this.anim.GetCurrentAnimatorStateInfo(0).IsName("fall"))
        {
            fall = false;
        }
    }    

    if(GameObject.Find("Stick_Figure_T-pose ragdoll(Clone)"))
    {
        Destroy(gameObject);
    }

    if(slider.value == 0)
    {
        MayJump = false;
    }
    else
    {
        MayJump = true;
    }
}