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

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

Asked by
Jirozu 71
7 years ago

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)
0
When charing is set to false, the while loop will end and the if statement will never execute Programical 653 — 7y
0
How can i fix that? Jirozu 71 — 7y

1 answer

Log in to vote
-1
Answered by 7 years ago

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)
Ad

Answer this question