Help! Player won't stop moving when I release the W key,Help! Player won't stop walking when I release the W key

So when I release the W key for a short second, it stops walking. But after a couple times it just continues walking and won’t stop. I’m following a Youtube tutorial and I don’t know where I’m going wrong.

Link to video: CHARACTER CONTROLLER WITH ANIMATIONS - WALK AND ATTACK - Unity 3D - Quick And Easy - YouTube

My code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class KnightController2 : MonoBehaviour
{

float speed = 4.0f;
float rotSpeed = 80.0f;
float rot = 0f;
float gravity = 8.0f;

Vector3 moveDir = Vector3.zero;

CharacterController controller;
Animator anim;

// Start is called before the first frame update
void Start()
{

    controller = GetComponent<CharacterController>();
    anim = GetComponent<Animator>();

}

// Update is called once per frame
void Update()
{

    if (controller.isGrounded)
    {
        if (Input.GetKey(KeyCode.W))
        {
            anim.SetInteger("condition", 1);
            moveDir = new Vector3(0, 0, 1);
            moveDir = moveDir * speed;
            moveDir = transform.TransformDirection(moveDir); 

        }
        if(Input.GetKeyUp (KeyCode.W))
        {
            anim.SetInteger("condition", 0);
            moveDir = new Vector3 (0, 0, 0);

        }
    }
    rot += Input.GetAxis("Horizontal") * rotSpeed * Time.deltaTime;
    transform.eulerAngles = new Vector3(0, rot, 0);

    moveDir.y = gravity * Time.deltaTime;
    controller.Move(moveDir * Time.deltaTime);
}

}
,So when I release the W key for a short time the player will stop walking, but after a few times it continues walking and won’t stop. Not sure what I’m doing wrong. I followed a Youtube tutorial and code seems to match…

Video I’m following: CHARACTER CONTROLLER WITH ANIMATIONS - WALK AND ATTACK - Unity 3D - Quick And Easy - YouTube

public class KnightController2 : MonoBehaviour
{

float speed = 4.0f;
float rotSpeed = 80.0f;
float rot = 0f;
float gravity = 8.0f;

Vector3 moveDir = Vector3.zero;

CharacterController controller;
Animator anim;

// Start is called before the first frame update
void Start()
{

    controller = GetComponent<CharacterController>();
    anim = GetComponent<Animator>();

}

// Update is called once per frame
void Update()
{

    if (controller.isGrounded)
    {
        if (Input.GetKey(KeyCode.W))
        {
            anim.SetInteger("condition", 1);
            moveDir = new Vector3(0, 0, 1);
            moveDir = moveDir * speed;
            moveDir = transform.TransformDirection(moveDir); 

        }
        if(Input.GetKeyUp (KeyCode.W))
        {
            anim.SetInteger("condition", 0);
            moveDir = new Vector3 (0, 0, 0);

        }
    }
    rot += Input.GetAxis("Horizontal") * rotSpeed * Time.deltaTime;
    transform.eulerAngles = new Vector3(0, rot, 0);

    moveDir.y = gravity * Time.deltaTime;
    controller.Move(moveDir * Time.deltaTime);
}

}

Same video and same problem. Have you figured it out? @nickleb