Im trying to make my own stamina system, and my script works almost exactly as intended with one minor problem.
local StaminaFunc = function(CurrentStam, IsRunning, PlrCar)
while IsRunning.Value do
if CurrentStam.Value > 0 then
CurrentStam.Value = CurrentStam.Value - 10
print(CurrentStam.Value)
wait(1)
else
PlrCar.Humanoid.WalkSpeed = 16
IsRunning.Value = false
end
end
end
local StaminaRegenFunc = function(CurrentStam, IsRunning, PlrCar)
while IsRunning.Value == false do
if CurrentStam.Value < 100 then
CurrentStam.Value = CurrentStam.Value + .5
wait(.5)
end
end
end
Im using functions and more the more specifically while loops to determine when someone loses stamina as you can see. However, this current code allows a player to technically have negative stamina. Because when the code subtracts the stamina it does not check if the stamina is above 0 until the next time the while loops cycles. Any ideas on how to make this more responsive. (and before anyone asks this is in a server script being triggered by a local script via a remote event)

2 comments
Thanks for your help but that will still lead to the same problem.
Then simply just use Double Constrained Values as im not that great at using LuaLibrary