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

I'm using a for loop for my stamina bar, but it only makes it go down, and does not go back up?

Asked by
wookey12 174
7 years ago
Edited 7 years ago

UPDATE! I figured out what was wrong. here's the code if anyone wants to borrow it.

-- Made by wookey12 :)
--[[Warning this script only PRINTS the Stamina amount in the output (just for the newbies)
    ]]

wait(1)
local player = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse()
local KEYRELEASED = true
mouse.KeyDown:connect(function(KeyDown)

    if KeyDown:byte() == 48 then
        KEYRELEASED = false
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 30


        for i = game.Workspace.StaminaVal.Value,1,-1 do

            print(i)
            game.Workspace.StaminaVal.Value = game.Workspace.StaminaVal.Value - 1
            wait(.5)
            if i == 1 then
                game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16

            end
    if KEYRELEASED == true then
                break

    end

        end

            end

end)

mouse.KeyUp:connect(function(KeyUp)
    if KeyUp:byte() == 48 then

KEYRELEASED = true
if KEYRELEASED == true then
        player.Character.Humanoid.WalkSpeed = 16
        for i = game.Workspace.StaminaVal.Value,30,1 do

                print(i)
                game.Workspace.StaminaVal.Value = game.Workspace.StaminaVal.Value + 1
                wait(.5)
                if KEYRELEASED == false then
                break
                end
                end
        end
end

end)

2 answers

Log in to vote
0
Answered by 7 years ago

I don't know if this will help, but try this:

-- Made by wookey12 :)
wait(1)
local player = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse()

while wait() do
    if KeyDown:byte() == 48 then
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 30
        for i = 30,1,-1 do
            if KeyDown == false then
                for i = i,30,1 do
                    print(i)
                    wait(.5)
                end
            end
            print(i)
            wait(.5)
        end
    else
    player.Character.Humanoid.WalkSpeed = 16
    end
end)
0
sorry, it doesn't work... i updated my script, maybe it will be simpler to work with? wookey12 174 — 7y
0
never mind i figured it out. I posted it in the answers if you want to see what i did. wookey12 174 — 7y
Ad
Log in to vote
0
Answered by
wookey12 174
7 years ago

UPDATE! I found out what was wrong. Here is my code if anyone wants to borrow it :)

-- Made by wookey12 :)
--[[Warning this script only PRINTS the Stamina amount in the output (just for the newbies)
    ]]

wait(1)
local player = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse()
local KEYRELEASED = true
mouse.KeyDown:connect(function(KeyDown)

    if KeyDown:byte() == 48 then
        KEYRELEASED = false
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 30


        for i = game.Workspace.StaminaVal.Value,1,-1 do

            print(i)
            game.Workspace.StaminaVal.Value = game.Workspace.StaminaVal.Value - 1
            wait(.5)
            if i == 1 then
                game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16

            end
    if KEYRELEASED == true then
                break

    end




        end


            end



end)

mouse.KeyUp:connect(function(KeyUp)
    if KeyUp:byte() == 48 then

KEYRELEASED = true
if KEYRELEASED == true then
        player.Character.Humanoid.WalkSpeed = 16
        for i = game.Workspace.StaminaVal.Value,30,1 do

                print(i)
                game.Workspace.StaminaVal.Value = game.Workspace.StaminaVal.Value + 1
                wait(.5)
                if KEYRELEASED == false then
                break
                end
                end
        end
end

end)

Answer this question