Hello, I have a sprint system in my game where if you hold T, you get faster and your stamina will decrease. Once you stop holding T and run out of stamina you will exponentially lose the WalkSpeed bonus and your stamina will regenerate.
Is there any way I could make this script shorter or more efficient? Thank you for any answers!
repeat task.wait(0.0425)
if Humanoid.WalkSpeed > 0 then
Stamina -= StaminaDeduction
Humanoid.WalkSpeed += 0.65
local Progress = (Stamina / MaxStamina)
TweenService:Create(Bar, StaminaTweenInfo, {Size = UDim2.fromScale(Progress, 1)}):Play()
Bar.Parent.Amount.Text = math.floor(Progress * 100)..'%'
end
until not UserInputService:IsKeyDown(Enum.KeyCode.T) or Stamina <= 0 or Jumping
task.wait(0.3)
repeat task.wait(0.065)
Stamina += StaminaDeduction
local Progress = (Stamina / MaxStamina)
TweenService:Create(Bar, StaminaTweenInfo, {Size = UDim2.fromScale(Progress, 1)}):Play()
Bar.Parent.Amount.Text = math.floor(Progress * 100)..'%'
if Humanoid.WalkSpeed > 0 then Humanoid.WalkSpeed -= 0.65
if Humanoid.WalkSpeed < 16 then Humanoid.WalkSpeed = 16 end
end
until Stamina == 10
if Stamina > 10 then Stamina = 10 end