Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make the script stop at 0 stamina?

Asked by
Prioxis 673 Moderation Voter
9 years ago

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

Log in to vote
0
Answered by 9 years ago

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.

0
Quick correction, after the loop stops, make sure to set stamina to 0 (stamina.Value = 0) just to make things easier when regenerating. Orlando777 315 — 9y
Ad

Answer this question