im trying to get my stamina system to work. theres a little bug however. everytime im standing still and spam shift, my stamina regens way faster than it should.
I tried using a variable to check if it was already running and to not loop again, but that didn’t work (shown here)
local isalreadyrunning = false
-- Restore stamina
while not Running and Stamina < StaminaMax and isalreadyrunning == false do
isalreadyrunning = true
Stamina += 1
print(Stamina)
wait(0.03)
if Stamina >= StaminaMax and frame.BackgroundTransparency == 0 then
makeTrs:Play()
makeBGTrs:Play()
isalreadyrunning = false
end
isalreadyrunning = false
end
– Restore stamina
function restoreStamina()
if isalreadyrunning then return end
isalreadyrunning = true
task.spawn(function()
while not Running and Stamina < StaminaMax do
Stamina += 1
print(Stamina)
wait(0.03)
if Stamina >= StaminaMax and frame.BackgroundTransparency == 0 then
makeTrs:Play()
makeBGTrs:Play()
end
end
isalreadyrunning = false
end)
What is the exact issue? Is the Regen regenerating too fast, or do you want a regen delay? (Waiting a few seconds after the player stops sprinting to regen.)