I honestly am clueless, I've tried something by the likes of this:
function decreaseStamina() while running == true do Stamina = Stamina - 1 print(Stamina) wait(.01) end end
but upon key release the loop would keep going.
I suggest UserInputService (LocalScript):
game:GetService("UserInputService").InputBegan:Connect(function(input) if input.KeyCode = Enum.KeyCode.LeftShift then -- Replace LeftShift with any KeyCode Stamina = Stamina - 1 print(Stamina) wait(0.01) end end)
Edit: Wrote "Conenct" instead of "Connect"
-- Put in StarterCharacterScript as a LocalScript local player = game.Players.LocalPlayer local character = player.Character local humanoid = character:WaitForChild("Humanoid") local input = game:GetService('UserInputService') local reloading = false local max_walkspeed = 32 local min_walkspeed = 16 local max_stamina = 30 local running = Instance.new("BoolValue") -- So we can use the Changed event local stamina = Instance.new("NumberValue") stamina.Value = max_stamina local function change_walkspeed(ws) humanoid.WalkSpeed = ws end local last_stamina = stamina.Value stamina.Changed:connect(function() print( (stamina.Value < last_stamina and 'Stamina Depleting: ' or 'Stamina Rising: ') ..stamina.Value ) last_stamina = stamina.Value end) running.Changed:connect(function() if running.Value then change_walkspeed(max_walkspeed) else change_walkspeed(min_walkspeed) end end) input.InputBegan:connect(function(inputType) if inputType.KeyCode == Enum.KeyCode.LeftShift and not reloading then running.Value = true while running.Value and stamina.Value > 0 do stamina.Value = stamina.Value - 1 wait() end -- while loop breaks and stops us from running running.Value = false if stamina.Value <= 0 then reloading = true end end end) input.InputEnded:connect(function(inputType) if inputType.KeyCode == Enum.KeyCode.LeftShift then -- If we let shift go and we're running, stop us. running.Value = false end end) while true do if reloading then -- if stamina is full if stamina.Value >= max_stamina then reloading = false else -- else deplete stamina.Value = stamina.Value + .5 end end wait() end