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

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

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

✓ Accepted answer

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)

2 comments

0

sorry, it doesn't work... i updated my script, maybe it will be simpler to work with?

0

never mind i figured it out. I posted it in the answers if you want to see what i did.

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)

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