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)
I'm currently working on something similar, but with capturing flags. Roblox's reaction time is a bit messy. So in order to actually make it stop I normally use
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 -----Less than, in case it goes negative sprinting = false end while sprinting do stamina.Value = stamina.Value -1 wait(.1) end player.Character.Humanoid.WalkSpeed = 16 end end)
But from my experience I would suggest the repeat until method like the other answer says, but use the ">" and "<" signs.