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