Player stamina

I want to limit the player stamina. You can use the

RestorePlayerStamina(PlayerId(), 1.0)

to set the player stamina at max, but I want to limit it, and it doesn’t seem to work if I use a negative number to decrease the stamina, but if I’m not at full stamina at use it with something like “0.2” it adds 20% to my stamina.
I have also tried to use

ResetPlayerStamina(PlayerId())

But that just sets the player stamina at full aswell

So does anyone know how to decrease the player stamina, or set it to a specific variable?

1 Like

Try something like this. It should limit the stamina to 100%

local currentStamina = GetPlayerSprintStaminaRemaining(PlayerId())
if currentStamina < 0.8 then
   RestorePlayerStamina(PlayerId(), currentStamina + 0.2)
end

If this was helpful please leave a like

1 Like

It doesn’t work.
To get the correct player stamina you have to do it like so.

    local currentStamina = 100 - GetPlayerSprintStaminaRemaining(PlayerId())

The stamina output u will get is between 100.0 and 0.0

   RestorePlayerStamina(PlayerId(),  1.0)

And this native uses values between 1.0 and 0.0

local currentStamina = GetPlayerSprintStaminaRemaining(PlayerId()) / 100f
if currentStamina < 0.8 then
   RestorePlayerStamina(PlayerId(), currentStamina + 0.2)
end

I have a problem, if I run the stamina does not go down, you can link the file with the script

Thats the purpose of the script. Have Unlimited Stamina.