when ever i click shift everything goes fine, but when i let go of shift i want the stamina to regen, and i want to be able to run at anytime as long as the stamina is above 0, but when i let go, i cant run anymore, i know i am doing something wrong.
---sprtsp = sprint speed ---regspd = regular speed ---maxstam = max stanima --- Vars local plr = game.Players.LocalPlayer local char = plr.Character local hum = char.Humanoid local sprtspd = 30 local regspd = 16 local maxstam = 100 uis = game:GetService("UserInputService") letgo = false ------------------------------------ uis.InputBegan:connect(function(input) if maxstam > 100 then maxstam = 100 end if input.KeyCode == Enum.KeyCode.LeftShift then while true do hum.WalkSpeed = sprtspd maxstam = maxstam - 1 wait(0.1) print(maxstam) if maxstam == 0 then hum.WalkSpeed = regspd elseif letgo == true then hum.WalkSpeed = regspd break end end end end) uis.InputEnded:connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then letgo = true while true do maxstam = maxstam + 1 wait(0.5) print(maxstam) if maxstam == 100 then return end end end end)
Just a simple problem of not setting the debounce back to false :) (letgo)
---sprtsp = sprint speed ---regspd = regular speed ---maxstam = max stanima --- Vars local plr = game.Players.LocalPlayer local char = plr.Character local hum = char:WaitForChild("Humanoid") local sprtspd = 30 local regspd = 16 local maxstam = 100 uis = game:GetService("UserInputService") letgo = false ------------------------------------ uis.InputBegan:connect(function(input) letgo = false -- here if maxstam > 100 then maxstam = 100 end if input.KeyCode == Enum.KeyCode.LeftShift then while true do hum.WalkSpeed = sprtspd maxstam = maxstam - 1 wait(0.1) print(maxstam) if maxstam == 0 then hum.WalkSpeed = regspd elseif letgo == true then hum.WalkSpeed = regspd break end end end end) uis.InputEnded:connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then letgo = true while wait(0.5) do maxstam = maxstam + 1 print(maxstam) if maxstam == 100 then return end end end end)