Help with Stamina System

Ok, so i’m making a first person game and i created a Stamina System and everything works fine but there is only one little problem, so when i press shift and i move, the character runs and stamina decreases but it also decreases when i stay still AND holding shift. I looked up on almost every youtube tutorial about stamina but they are all the same and no one seems to notice this problem. Below you have my blueprints, i would appreciate it a lot if you guys could try and help me with some screenshots of the blueprints if you have any, it would make me understand better in that way because i’m still a noob at UE4, but any help is appreciated. Thank you and i’m sorry if i spelled something wrong, english is my second language.

  1. I would recommend creating a variable called MaxStamina (Set this to 100) This will be your variable for change within your stamina system. Use that variable to divide Stamina by Max Stamina in your widget blueprint.
  2. Your general idea for the system you are trying to create seems to function properly in a sense. However, there are a few holes that could break this system. I would recommend using a float instead of an integer and clamp the value of Stamina to MaxStamina on beginplay and every time the player might get an upgrade that increases MaxStamina.

If you would like additional help, PM me your discord username and I will assist you.

At the bottom of the first screenshot blueprint, there’s a check on stamina being <= 0…why less than or equal to zero? is stamina going below 0 in the system at all? or is it a safeguard in case something in the system puts it below 0 inadvertently?

the other thing in the lower part there is after that check, it connects eventually to a node saying “has stamina” after a Boolean test of true. If stamina is less than or equal to 0, how would the Boolean evaluate to true? that may be what’s causing the standing still stamina drain while holding the sprint/run key (Shift) because the system is basically evaluating stamina as being infinite in the negative direction ( <= 0 ). The solution?

Part of it is to change the lower left check on stamina from <= to simply = or ===.
The system appears to need a stamina regeneration function, unless there’s more not in the screenshots that does it.
@SolidGasGames is correct. It needs to run the check for no stamina and change it based on “velocity is 0” and no keys pressed to activate stamina drain.
In the second screenshot where it is applied to character, why is there a dot product node followed by a divide node (by 100) using a percentage from the previous nodes? Multiplying a percentage to a dot product of another number is going to alter that number wrongly before dividing, unless it’s multiplying it by 100, in which case there’s no point in doing so because it is then divided by 100. In other words, if the stamina is 75%, or 0.75, multiply it by 100 = 75.0, then divide by 100 = 0.75, it’s back where it started lol. Is there a reason for that workup?

Can you confirm the IsSprinting is actually changing to false? You only change it if it is 0 or less, you should also change it when the velocity is 0 or no movement keys are pressed.

Show image of blueprint

You need to implement a clamp in-between your subtraction and set while sprinting

Stamina → int - int —> Clamp (integer) —> Set Stamina.

Can replace with floats too.