local stamina = Instance.new("IntValue")
stamina.Name = "Stamina"
stamina.Value = 100
stamina.Parent = script.Parent
local running = false
local humanoid = script.Parent.Humanoid
function regen ()
while true do
while stamina.Value < 100 and running == false do
print("Regenerating..", stamina.Value)
wait(0.1)
stamina.Value = stamina.Value + 1
end
stamina.Changed:Wait()
end
end
spawn(regen)
function onKeyPress(actionName, userInputState, inputObject)
if userInputState == Enum.UserInputState.Begin then
print("Running")
running = true
end
if userInputState == Enum.UserInputState.End then
print("Walking")
running = false
end
end
game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.LeftShift)
This is a test script i made for sprinting so not all parts is included but still works the same way, this is a local script inside the StarterCharacterScript. The concept is that while I'm not running I'm regenerating 1/100 stamina every second if my stamina is not 100, while running I'm loosing 2/100 stamina every second. The problem is when I started running my stamina won't regenerate (which is how it's supposed to work)
but when i stopped running my stamina still doesn't regenerate
, when I change the value of the stamina to something lower than 100 via explorer it starts to regenerate again.

7 comments
Do you have something in the script that makes the player lose stamina while they're running? When I tested your script, I saw that it did print "running" and "walking" at the right times, but the value of stamina doesn't go down at all (in which case it wouldn't regenerate, because stamina.Value < 100 isn't true).
I told that this script is a test script, not all parts are included but everything works the same way, the part where the player lose stamina is removed since its not the problem and may confuse the readers
You can change the value via explorer, it works the same way.
It doesn't show any errors, copy pasting this code and running it wont show any results.
I added print("Running") and print("Walking") to show that the sprint function itself works
Did you try changing while stamina.Value < 100 and running == false do to if stamina.Value < 100 and running == false then
the question is already answered.