Trouble with Sprint/Stamina Mechanic

Hey so I was making a stamina mechanic for a game of mine and it basically does what it is meant to do but its super janky. I mainly followed this tutorial by Gorka games, I don’t know if its out dated or if I’m just doing something wrong: https://youtu.be/jtJddy6zgqA?si=mKmIgsWtd1OHoK1x

Here is the code that I put together:

(Sorry for the poor quality)

And here are the variables that are used:

Screenshot 2026-01-31 003535

The main problem that I have been seeing are the regenerate stamina and use stamina are happening at the same time and cause the actual action of sprinting to be canceled out. I think the problem is happening with this section of the code:

But I can very much be wrong, I haven’t been coding for that long so I just want to know what’s going wrong so I can fix this code in whatever way I need to. Something I wanted try is to add a delay (Which didn’t work) or have it some how disable the use function while the regeneration is happening, like make it so that when the player is stopped then the player can regenerate stamina.

regardless I don’t know how to fix this so if someone knows how please let me know.