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

A "if" for two different values?

So.... I need a way to do a "if" thing for two values, this:

if RandomBall and Ball1BeingUsed == ?????????? then

The ???????????? is the problem, I mean, that RandomBall is a number value, and Ball1BeingUsed is a bool value, so they're two different value types. So that means how would I do that, I'm guessing I'll try a "and" like this "== 1 and false then" but I'm not sure it works........

1 comment

1

For future reference: and makes the if function fire ONLY if both conditions are valid! or will fire the function if EITHER condition is valid!

2 answers

✓ Accepted answer

Lol, you had it almost exactly correct. This'll work:

if RandomBall== 1 and Ball1BeingUsed == false then --You can change the '1' or 'false' if you need to

It doesn't matter how many conditions there is, which I think was your problem. You don't assign them both to the same value when you use "and", you're just setting up another condition. Hopefully you understand what I'm trying to say. Anyways, if you have any questions or problems, please leave a comment below. Hope I helped :P

3 comments

3

Ball1BeingUsed == false is the same as not Ball1BeingUsed, the latter being more readable. :D

0

It works...!

0

Awesome! Glad I could help :P (Upvoted adark)

I'm not sure what you're trying to ask here.

and is a binary operator (meaning it works on 2 things). If the first operand is true or truthy (that is, if it isn't false or nil), the second is returned, otherwise the first is returned.

or is also binary, but is the opposite. If the first operand is not true or truthy, the second is returned, otherwise the first is returned.

In your example,

if RandomBall == 1 and not Ball1BeingUsed then --This is what I assumed you meant.

--First, it checks `RandomBall == 1`. If it is indeed 1, this becomes:

if Ball1BeingUsed then

--and if it isn't:

if false then

--Which obviously does nothing.

--Next, if `Ball1BeingUsed` is `true` or not-`nil` then the `if` statement runs. Otherwise, nothing happens again.

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