How do i lower a value over time?

im trying to create a stamina type of thing for sprinting. how do i get the stamina value to go down over time? also, how do i get the sprinting to stop once the staminas value is 0?

There are many way to do it. The most straight-forward way (does not mean most efficient) would be to decrement the said stamina within the Tick event. Make use of the delta time (So stamina = stamina-delta_time*rate_of_depletion) Once you have decremented the stamina, use a branch and check if it has hit 0 or less. In that case, stop the spriting animation and lower the characters movement speed.

For the above method to work, you must have a variable to hold the stamina, which you are modifying in each tick. On the Action event for sprint, check this variable before you trigger sprinting.

In my game based off of ShooterGame, I made this code that is placed in void AShooterCharacter::Tick(float DeltaSeconds). The first part is regenerating stamina, while the second part is using it during running. While you want to use it sparingly, Tick is a great function for things that need constant updating.

/** Regenerate stamina if not running, or drain it if running. */
if (this->Stamina < this->GetMaxStamina() && !IsRunning())
	this->Stamina += 1 * DeltaSeconds;
	if (Stamina > this->GetMaxStamina())
		Stamina = this->GetMaxStamina();
if (IsRunning())
	this->Stamina -= 1 * DeltaSeconds;
	if (Stamina <= 0)
		Stamina = 0;
		SetRunning(false, false);

EDIT: Sorry, I did not realize this was in Blueprint scripting. As the other answer says, you can still use Tick to update it over time.

Its been a while, and we haven’t heard from you since. So I am going to assume that the issue is solved.

Marking this as right answer.
@alx0427: If the issue is not yet resolved OR if this is not the right answer, let us know by adding a comment.

I actually just recently solved the same problem that you asked about. What I found is that using delta seconds causes a lot of bugs that are difficult to fix. I found that the better solution was to rather use delay loops in which you ask if you are sprinting. If you are, then check to see if you have stamina remaining. If you do, then add a short duration delay (like .005) and then set the stamina to slightly less, then check to see if you still have stamina remaining, and then check to see if the player is still sprinting. If so, then loop back to the delay.

This, similarly, can be done for automatic stamina regeneration. Hope this helps anyone that sees this post!