Decreasing Slider value if a button is pressed

I’m new to unity and I have a problem with the slider option in unity. What I have been trying to do is that if the left shift key is held down the staminaslider.value will decrease and when its released it goes back up. But I haven’t figured a way to fix this.

The code I’m using:

if (Input.GetKeyDown(KeyCode.LeftShift) && (currentStamina > 0))
        {
            currentStamina -= Time.deltaTime;
            speed = (7.0F);
        }
        if (Input.GetKeyUp(KeyCode.LeftShift))
        {
            speed = (5.0F);
            currentStamina += Time.deltaTime;
        }
        StaminaSlider.value = currentStamina;

@Fullmetal16 Are you using ‘void Update()’ ? Because, if you use this in ‘void Start()’ or ‘void Awake’ it will not work at all !
But I can’t see all of your code so I make my opinion for the Update function !

@Voyder_Rozann yes all of this is in the void update ()