Hi,
I made this sprinting script. The problem is if you SPAM left shift, and you wait till regeneration it goes really really quick. I know the logic issue, but not a fix. Does anyone know how to fix?
--Sprinting & Stamina
local Stamina = 100
local Running = false
UserInputService.InputBegan:Connect(function(Input, GPE)
if Input.KeyCode == Enum.KeyCode.LeftShift and not GPE then
if not Running then--Stamina >= 100 and not Running then
Running = true
Character.Humanoid.WalkSpeed = 24
while Stamina > 0 and Running do
Stamina -= .5
Player.PlayerGui.SprintUI.StaminaUI.Holder:TweenSize(UDim2.new(Stamina / 100, 0, 1, 0), "Out", "Linear", 0)
task.wait(.01)
if Stamina <= 0 then
Character.Humanoid.WalkSpeed = 16
script.Sound:Play()
end
end
end
end
end)
UserInputService.InputEnded:Connect(function(Input, GPE)
if Input.KeyCode == Enum.KeyCode.LeftShift and not GPE then
Running = false
Character.Humanoid.WalkSpeed = 16
task.wait(2)
if not Running then
while Stamina < 100 and not Running do
Stamina += .25
Player.PlayerGui.SprintUI.StaminaUI.Holder:TweenSize(UDim2.new(Stamina / 100, 0, 1, 0), "Out", "Linear", 0)
task.wait()
if Stamina <= 0 then
Character.Humanoid.WalkSpeed = 16
elseif Stamina >= 100 then
script.Sound:Stop()
Player.PlayerGui.SprintUI.StaminaUI.Holder.Size = UDim2.new(1,0, 1,0)
end
end
end
end
end)