Help with stamina system

I have a stamina system in my game and i want that everytime a player stops sprinting they need to wait 2 seconds for the stamina to regenerate. I made a separate function for it using a task.wait, it stops the stamina from regenerating and after two seconds it starts to regenerate and i spawned it whanever the player stops sprinting.

What’s the issue? If a player spams the left shift (the sprint input) sometimes it bypasses the wait and they do not need to wait those 2 seconds to their stamina to regenerate.

I tried using if statements inside the first function but it still manage to get bypasses, how can i fix that?

I’m assuming you’re using task.delay to schedule the ‘regenerate’

If so, I would make a variable with the task.delay and whenever leftshift is pressed, task.cancel(variable) to stop it from running any further

Code?
char minimum char minimum

1 Like

i placed the task.cancel inside the UIS function and inside the regenerate function a print, i also made the threat like you said and i used task.delay to call the threat when the player stops sprinting, however nothing happends and not even the print does anything