I wrote this little sprinting script and have a conditional loop running that every 1 millisecond it takes away 1 stamina but I want it to stop at 0 and i've tried a few things and nothing happened
here's my script
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local empty = false
local stamina = Instance.new("NumberValue", player);
stamina.Value = 100
local sprinting = false
Mouse.KeyUp:connect(function(shiftUp)
if shiftUp:byte() == 48 then
sprinting = false
end
end)
Mouse.KeyDown:connect(function(shiftDown)
if shiftDown:byte() == 48 then
player.Character.Humanoid.WalkSpeed = 45
sprinting = true
if stamina.Value ==0 then
sprinting = false
end
while sprinting do
stamina.Value = stamina.Value -1
wait(.1)
end
player.Character.Humanoid.WalkSpeed = 16
end
end)

1 comment
Quick correction, after the loop stops, make sure to set stamina to 0 (stamina.Value = 0) just to make things easier when regenerating.