First of all the staminabar, which is a frame, doesn't "react" when you press LeftShift first and then the W key. Then sometimes it gets stuck when its at 0 stamina and you can run forever. The last problem is that you can drain your stamina while standing still. Please someone help! Here's the code:
local character = player.Character
local hum = character:FindFirstChild("Humanoid")
local UserInputService = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local stamina = 200
local running = false
stamina = math.clamp(stamina,0,100)
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
running = true
character.Humanoid.WalkSpeed = 14
while stamina > 0 and running do
stamina = stamina - 1
script.Parent:TweenSize(UDim2.new(stamina / 100,0,1,0), "Out","Linear", 0)
wait()
if stamina == 0 then
character.Humanoid.WalkSpeed = 8
end
end
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
running = false
character.Humanoid.WalkSpeed = 8
while stamina < 100 and not running do
stamina = stamina + .5
script.Parent:TweenSize(UDim2.new(stamina / 100,0,1,0), "Out","Linear", 0)
wait()
if stamina == 0 then
character.Humanoid.WalkSpeed = 8
end
end
end
end)
If you want to test it, place the localscript under a staminabar frame in startergui. Thanks!

2 comments
thx for the help!
No Problem