Add Stamina Problems

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)
image
image

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
image

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

image

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 :sob:

Thanks

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

PS: Change #help-and-feedback:creations-feedback to #help-and-feedback:scripting-support

3 Likes

Not exactly working but helps, The idea helped me to getting closer to finding a fix though. Thanks!

2 Likes

I have another question,

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

Im very confused :sob: :sob:

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.

2 Likes

now when I recover stamina it sets itself to Max Stamina, confused so much

When you recover stamina, is print("im recovering normally") printing or the print("Last recovery collision done..") printing?

1 Like

it prints print(“Last recovery collision done…”)

1 Like

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.

2 Likes

this is how I drained it

how i make the ragdoll get up

more script for context

thats pretty much everything i think
sorry for not showing more context

1 Like

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.

1 Like

its printing normally,
image

its printing the latest value of stamina whenever its changing aswell
image

I honestly dont know what im doing wrong

Then the only thing I can think of that could be wrong is MaxStamina.Value. Try printing MaxStamina.Value to see if it is the correct value.

1 Like

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

2 Likes

How do you think i could apply it? is it while im adding my stamina? sorry this is the first time im gonna use math.clamp

Thanks J_Angry for your effort bro

1 Like

Seems you figured it out. Nice :smile:

Yep. And also learned about math.clamp just today thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.