InvokeRepeating/CancelInvoke not working

so some background on what im doing
im trying to make a stamina bar that when the player runs it depletes “current stamina” from the “max stamina” and over time the “currently attainable stamina” depletes as well passively. this all works but now I want it so that when the player runs the “currently attainable stamina” will deplete faster than the passive stamina depletion.
the way ive set this up is by having a player controller script and a stamina bar script, when you press left shift down it gets stamina bar script then invokes the function to deplete it and sets a bool to true that activates something else, and then i have an if statement in my update function stating that if that bool is false cancel the invoke but it dosent despite having a debug log telling me that its getting past that.
am i using this wrong or dose anyone have any other suggestions on how to approach this ? i am still new enough to coding btw

void HandleRunInput()
    {
        if(Input.GetKeyDown(KeyCode.LeftShift))
        {
            isRunning = true;
            Sb.InvokeRepeating("GettingTiredStaminaDepleation", 1.0f, 1.0f);
            Debug.Log("Invoked");
        }
        if (Input.GetKeyUp(KeyCode.LeftShift))
        {
            isRunning = false;
        }
}
void Update()
    {
        if (isRunning == false)
        {
            CancelInvoke("GettingTiredStaminaDepleation");
            Debug.Log("Invoke Cancel");
        }
    }

side note i have tried cancelInvoke without the string name as well and i have tried putting it in the Input.GetKeyUp statement but still no success

Firstly, you didn’t need to make another thread with the same problem. You could have continued on from your previous thread.

Invoke, InvokeRepeating, etc, are pretty old functions that are from the early days of Unity. They’re kind of bad practice these days and it’s best to not get into the habit of using them.

It’d be much easier to just increase/decrease your stamina depending on whether you’re running or not in an update loop:

//in player controller
public void Update()
{
    if (Input.GetKeyDown(KeyCode.LeftShift))
    {
        staminaBar.isRunning = true; //give your values descriptive names
    }
   
    if (Input.GetKeyUp(KeyCode.LeftShift))
    {
        staminaBar.isRunning = false;
    }
}

public class StaminaBar : Monobehaviour
{
    public bool isRunning = false;
   
    private void Update()
    {
        if (isRunning)
        {
            //decrease stamina
        }
        else
        {
            //increase stamina
        }
    }
   
}

This of course doesn’t show how to prevent or stop running when stamina runs out, but that’s something for you to learn as you go.

oh sorry makes sense i probably should have continued on the same thread its just this is a different issue im having on the same script. i also didn’t realise invoke was bad practice if that’s the case can you point me in the right direction for what i want to achieve, i can probably explain this a little better.
the stamina bar is recording 3 values one is the max stamina one is displaying how much of that stamina is currently being used and the other is how much can be recharged (currently obtainable stamina) i have a system that depletes the currently obtainable stamina passively at a slow rate but now i want a new condition to deplete it slightly faster when the player starts running and then stop when they aren’t running. The way i thought of doing this was by having it tick down by 1 every 2 seconds the player is running and when they stop running that stops. with the bit of code i have now when you run it ticks down by 1 every 2 second but cancel invoke docent stop the invoke and then if i keep pressing the shift button the invoke stacks.
i have tried it the way you’ve shown but that depletes it way too fast and ive tried an IEnumerator but that also stacks and depletes it way too fast.
so is there a better way of ticking down the int (currently obtainable stamina) by 1 every 2 seconds when the player is running

Then just… decrease it less? Use a value of a magnitude that you can decrease over a reasonable time. And don’t use int, use a float here.

A float of value 1 would take 1 second to reduce to zero if you decreased it by Time.deltaTime each Update.