Multiple Conditions if statement

So I’m probably being really stupid but I forgot how to use multiple conditions on an if statement without using elseif. I’m trying to make a TextBox reader & need it to have 2 passwords without using elseif. Here is my code:

Confirm.MouseButton1Click:Connect(function()
	if Code.Text == "Password" then

I want to be able to do something like this:

Confirm.MouseButton1Click:Connect(function()
	if Code.Text == "Password", "Password2" then
1 Like

Use either or or and
example–

if 1 and 2 < 3 then
print("and condition passed.")
end

if 1 or 2 == 2 then
print("or condition passed.")
end

I’m trying to do

if 1 == 1 or 2 then

but that didn’t seem to work…

Are you trying to do this?

if Code.Text == "Password" or Code.Text == "Password2" then
3 Likes

You’ve already gotten the answer to your question, but if you ever want to have a lot of passwords, it might make more sense to put them all in a table and then use table.find(passwords, text) to see if the entered text matches a password.

5 Likes

Source:

You would need to treat it as 2 separate conditions
so condition 1:
if Code.Text == “Password”

and condition 2 being
if Code.Text == “Password2”

now we only need 1 if statement because we can use an or. But the conditions should remain the same. Therefore we get:

if Code.Text == “Password” or Code.Text == “Password2” then

end

This is because lua treats each side of the or statement as a separate condition.
The same goes for and statements.

1 Like

Thanks this worked. I knew I was just being really stupid.