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

I am tried to make a sprint button with an energy (stamina) and it isn't working can anybody help?

Asked by 3 years ago

My script will not remove any stamina and I don't know what I have done wrong please help here is the script

=

local player = game.Players.LocalPlayer

local UserInp = game:GetService("UserInputService")

local ShiftPressed = false

local stamina = 100

local function ChangeWalkSpeed(Player, NewWalkSpeed) if Player and Player.Character then if Player.Character:FindFirstChildWhichIsA("Humanoid") then Player.Character:FindFirstChildWhichIsA("Humanoid").WalkSpeed = NewWalkSpeed end end end

ChangeWalkSpeed(player, 9)

UserInp.InputBegan:Connect(function(input)

if input.KeyCode == Enum.KeyCode.LeftShift then

    if stamina >= 1 then

    ShiftPressed = true

    while ShiftPressed == true do
        wait()
            ChangeWalkSpeed(player, 36)

            end

    end

end

end)

UserInp.InputEnded:Connect(function(input)

if input.KeyCode == Enum.KeyCode.LeftShift then

    ShiftPressed = false

    while ShiftPressed == false do
        wait()
        ChangeWalkSpeed(player, 9)
    end

end

end)

while true do

wait()

if ShiftPressed == true  then

    wait(0.009)

    stamina = stamina - 1

end

if stamina <= 99 then

    print("work")

    wait(0.8)

    stamina = stamina + 1

end

if stamina <= 1 then

    wait()

    ShiftPressed = false

end

print(stamina)

end

Answer this question