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

My IF Statement is not working, it involves IF OR and AND?

Asked by 8 years ago

if workspace.C.REDD.RED.BrickColor==BrickColor.new("Really red") or workspace.C.REDD.RED.BrickColor==BrickColor.new("Bright red")or workspace.C.REDD.RED.BrickColor==BrickColor.new("Persimmon") and workspace.C.BLUEE.BLUE.BrickColor==BrickColor.new("Really blue") or workspace.C.BLUEE.BLUE.BrickColor==BrickColor.new("Bright blue")or workspace.C.BLUEE.BLUE.BrickColor==BrickColor.new("Electric blue") and workspace.C.WHITEE.WHITE.BrickColor==BrickColor.new("Ghost grey") then Message=Instance.new("Message",workspace) Message.Text="YOU WIN!" wait(3) Message:Remove() end

C is the main parent, REDD is the child of C but the parent of RED. When I change the colors to what it's supposed to be the message that is supposed to appear does not show up.

0
Sorry that the title is weird, the website wouldn't let me post without a specific title Earthkingiv 51 — 8y
0
What does "not working" mean? Can you explain in simple English what you expect it to do? BlueTaslem 18071 — 8y
0
OK so there is three parts, each part has a code that changes its color when you click it. This code is supposed to make a message appear when you get all three of the right colors at the same time. Earthkingiv 51 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

The issue with your script is that you are trying to put everything on a single if statement. You tell it to check for three brickcolors, then you use and to check for the other colors. When you use the and, it only affects that specific statement after the and. The or that comes after is not connected to the and, making it a entirely different statement that can pass all the other ones. To fix it I would make if statements that check for each brick separately

01PartOneCorrect = false
02PartTwoCorrect = false
03PartThreeCorrect = false
04 
05if PartPath.BrickColor == BrickColor.new("Really red") or PartPath.BrickColor == BrickColor.new("Bright red"or PartPath.BrickColor == BrickColor.new("Persimmon") then
06    PartOneCorrect = true
07end
08 
09if PartPath.BrickColor == BrickColor.new("Really blue") or PartPath.BrickColor == BrickColor.new("Bright blue"or PartPath.BrickColor == BrickColor.new("Electric blue") then
10    PartTwoCorrect = true
11end
12 
13if PartPath.BrickColor == BrickColor.new("Ghost grey") then
14    PartThreeCorrect = true
15end
16 
17if PartOneCorrect == true and PartTwoCorrect == true and PartThreeCorrect == true then
18    --Run what code you want to run here
19end
Ad

Answer this question