How can I do this?

Ive recently made a boost system where touching something gives you a boost and it slowly fades away (and touching it again will increase it again) This will not only boost your health, but other things such as stamina. While I was trying to make this work for stamina I got stuck. This is because the boost goes down every 1-3 seconds. and During that time, the stamina could either increase or decrease depending on if the player sprinted or not. When I try to think of ways to do this with keeping the ratio of stamina to max stamina the same, I got really stumped. The way I did it for the max stamina was I had a “Original” stamina Attribute and I would add the boost from there which would look something like this:

local function syncStaminaToBoost(BoostMultiplier,MaxStamina)
local originalStamina = MaxStamina:GetAttribute("OriginalStamina")
 MaxStamina.Value = originalStamina * Boostmultiplier

However, this only works because the “OriginalStamina” attribute wont change. Does anyone know how I could also keep the stamina to max stamina ratio the same? (if max stamina is 5 and normal stamina is 2, it would be 4 to 10 if the multiplier was 2.)


Boost should not be linked to stamina; it should be separate. You should regenerate stamina to the max possible and a boost would go above that level. Unless this boost “heals” stamina, they should be separate.

1 Like

Think of the boost as a stat increase boost. It will increase some stats supposedly when you touch a part or if you are low on hp. One of these stats include stamina, but others like speed and strength are also effected by it.

I don’t expect stamina to go over 100% if it is managed by another thing. If it was regenerated to 100%, I can see that just fine. If originalStamina was over 50% of the max and Boostmultiplier is 2, then the stamina would go over the desired max amount.

So, I recommend using math.clamp to keep the value from going over. If you are planning for a temporary increase of speed, I recommend using a different attribute.

I dont think I explained well enough.

Basically, “originalStamina” (which should probably be named to originalMaxStamina) is the maxStamina that the player has without any boosts. The attribute is just there so the max stamina will eventually settle down to its original self. (the function is in a loop and the multiplier decreases until it becomes one) The thing im wondering is how I could also make the normal stamina still have the same ratio with max Stamina. (I’ve tried various different things which didnt work)