Heres my problem, Everything in my stamina system works and all. but the problem is, Im trying to create a training system for the stamina, originally this is how I add the stamina (when regening)
When making the training system, im gonna add the value to max stamina since the staminas limiter is max stamina.
My problem (example)
Percentage Stamina = 3
If Max Stamina = 102
Stamina will add up to odds, and then also go way past the Max Stamina limit and will continue to regen, just like this
do you guys have any idea to fix this? something like making percentage stamina round up to the max stamina value when its gonna go past the stamina limit,
because i have no idea as a new scripter
Try this, which rounds to max stamina if it’s going over:
local MaxStamina -- define this as your MaxStamina StringValue
local FinalRecovery = Stamina.Value + PercentageRecovery
if FinalRecovery > MaxStamina.Value then
FinalRecovery = MaxStamina.Value
end
Stamina.Value = FinalRecovery
im executing your idea here, but when stamina goes over max stamina
stamina > maxstamina is still true
how???
when stamina is lower than max stamina its true
when stamina is higher than max stamina its true again
when stamina and max stamina is equal its false
I think you switched the code for Stamina.Value > MaxStamina.Value, and Stamina.Value < MaxStamina.Value. For example, for Stamina.Value < MaxStamina.Value, You set the value of Stamina to MaxStamina, even though Stamina is less than MaxStamina.
Is there any more of the script you can show? I’m confused how Stamina.Value is higher than MaxStamina.Value if Stamina.Value never increased at all.
Everything seems fine. Try inserting print(Stamina, PercentageRecovery) before Stamina.Value = Stamina.Value + PercentageRecovery. I assume one of those variable is wrong, because there’s only one line where you add stamina, and those are the only two variables used. Inform me if I’m wrong about there only being one line where you add stamina, as that could be causing the issue instead.
You can clamp down your values with math.clamp so they don’t go lower or higher than what you set.
Example:
math.clamp(101, 0, 100) -- Will be 100 because maximum is 100
math.clamp(-1, 0, 100) -- Will be 0 because minimum value is 0
math.clamp(99, 0, 100) -- Value will be the same (99) and nothing will be the same because it's not past the limits
Edit: math.clamp first takes in the value you want to clamp, your minimum value, and finally your maximum