"or" does not work?

Hey so I have a specific thing in my game that only certain players can use.
2 players to be exact.
I have it so when u click a button it checks your user id
the script is something like this

button gets pressed
if plr.UserId == (X or Y) then

X user can access the button but for some reason the person with the Y userId cannot
WHy is this? (the user ID is accurate)

Try defining an array in a variable before the function.

if plr.UserId == X or plr.UserId == Y then

do if plr.UserId == X or plr.UserId = Y

Obviously it doesn’t work because you put the parentheses. The compiler will think that if X has a value then the parentheses will be true, resulting your if statement to become like this:
if plr.UserId == true then

1 Like

That’s not exactly correct, it wouldn’t return a boolean unless you’re doing a direct comparison doing ==.

(X or Y) will return X because it’s deciding which value is true or isn’t nil.

Ah I realized my issue now lol
thank you all for the help @impreeminent @GetGlobals @aaltUser

Right, but still, if X has a value, it become a true-ish value. However, if X fails then Y will take over. Can I have your opinions on why this doesn’t work?

(X == Y) will return true or false because you’re doing a comparison against the values.
(X or Y) will either return X or Y not a boolean because it’s going to move on from X if it’s nil(or false) and return Y.

local X = 5
local Y = 6

print((X or Y)) -- Output: 5
print((X == Y)) -- Output: False

So then if X does have the value, would it be this?
if plr.UserId == 1763733737
X is that giberish number by the way.

Yes, it would choose X first making it that ID for the UserId to be compared.

So unless X is nil it won’t compare the Y value since X will always be true/exist

But then, why wouldn’t it work in this case?

Because, when it’s processing the if statement the values before and after == are handled first before being compared to one another.

if (5 == 6) == (3 == 2) then
print("yup")
end

-- Outputs yup because both values are false after being processed before being compared in the if statement.

That doesn’t make any sense to me. Can you be more clear?

When a if statement is being processed it’s broken down into these components before the FINAL values are compared.

if (5 == 6) == (3 == 2) then

It will take (5 == 6) run the ternary and return false
It will then take (3 == 2) run the ternary and return false

it then boils down to

if false == false then

Now when you do UserIds

X = 123508
Y = 122353

if Player.UserId == (X or Y) then

Takes Player.UserId returns Player.UserId
Takes (X or Y) and returns X

then it becomes

if Player.UserId == 123508 then

So? Where’s the issue? It seems like everything went smoothly.

He’s trying to check for two different UserIds but will always check one because it’s returning X and will never return Y since X will always exist.

His script will always check X(123508) and will never check Y(122353) when he’s trying to check both X and Y

Oh, now that makes more sense. Thanks.

My bad that I wasn’t clear enough, you have a good night/day.