I’m making a sprint script for my game but it appears i am in abit of a pickle.
When i hold down shift and hold any of the movement keys, the stamina should decrement by 1 every 0.1 seconds. And when i let go of the movement keys (with shift still held down) the stamina should stop decrementing. Very simple to make, yes… However, my greatest enemy known only as “My inability to problem solve” has come back to haunt your great hero once again.
While it is true that when i release the movement key while holding shift, the stamina stops decrementing. When i press the movement keys again, the stamina doesnt continue decrementing!!! Shocking. I know.
With that being said here is my script:
local stamina = 100 userInput.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then cameraFovTweenOut:Play() crouchwalkAnimTrack:Stop() crouchAnimTrack:Stop() crouching = false running = true if humanoid.MoveDirection.Magnitude ~= 0 then humanoid.WalkSpeed = 25 cameraFovTweenIn:Play() while running do wait(0.1) stamina -= 1 print(stamina) if humanoid.MoveDirection.Magnitude == 0 then running = false end if running == false and humanoid.MoveDirection.Magnitude ~= 0 then running = true end userInput.InputEnded:Connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then cameraFovTweenOut:Play() running = false humanoid.WalkSpeed = 16 end end) end end end end
Condition 1: When i hold shift and WASD my stamina goes down(Intentional)
Condition 2: When i keep holding shift and release WASD my stamina stops going down(Intentional)
Condition 3: when i still keep holding shift and press WASD again my stamina doesnt go down like in condition 1 like its supposed to (Problem)
PS: I havent coded in the part where you regenerate stamina or stop sprinting when you run out of stamina so for now stamina is just a number that goes down when you sprint