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

"Or" function in my script not doing the code under it, how to fix?

So, to make this simple, this script is like a adding number script, but once it gets to the

break end

then it stops and does the code below. But i have having some problems as once it gets to the

or Charing == false then  

It doesnt print the code under below. Is there a simple fix for this?

local Player = game.Players.LocalPlayer
local Charge = 0
local Charing = false
local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(input)
	if input.KeyCode ~= Enum.KeyCode.H then return end;
	Charing = true
	game:GetService("Chat"):Chat(Player.Character.Head, "HERE I GO...")
	while Charing == true do
		print(Charge)
		Charge=Charge+1
		if Charge == 120 or Charing == false then 
			print("aaa")
			game:GetService("Chat"):Chat(Player.Character.Head, "HA!")
			break end
		wait()
	end
end)

UIS.InputEnded:connect(function(input)
	if input.KeyCode ~= Enum.KeyCode.H then return end;
	Charing = false
	Charge = 0
end)

2 comments

0

When charing is set to false, the while loop will end and the if statement will never execute

0

How can i fix that?

1 answer

You could ditch the or and just use an elseif statement instead:

local Player = game.Players.LocalPlayer
local Charge = 0
local Charing = false
local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(input)
    if input.KeyCode ~= Enum.KeyCode.H then return end;
    Charing = true
    game:GetService("Chat"):Chat(Player.Character.Head, "HERE I GO...")
    while Charing == true do
        print(Charge)
        Charge=Charge+1
        if Charing == false then 
            print("aaa")
            game:GetService("Chat"):Chat(Player.Character.Head, "HA!")
            break end
        elseif Charge == 120 then -- Use elsif
            print("aaa")
            game:GetService("Chat"):Chat(Player.Character.Head, "HA!")
            break end
        wait()
    end
end)

UIS.InputEnded:connect(function(input)
    if input.KeyCode ~= Enum.KeyCode.H then return end;
    Charing = false
    Charge = 0
end)

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