Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make the script stop at 0 stamina?

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 answer

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.

1 comment

0

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

This discussion is preserved as it was. New answers, comments, and votes are closed.