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 7 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 — 7y
0
What does "not working" mean? Can you explain in simple English what you expect it to do? BlueTaslem 18071 — 7y
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 — 7y

1 answer

Log in to vote
0
Answered by 7 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

PartOneCorrect = false
PartTwoCorrect = false
PartThreeCorrect = false

if PartPath.BrickColor == BrickColor.new("Really red") or PartPath.BrickColor == BrickColor.new("Bright red")  or PartPath.BrickColor == BrickColor.new("Persimmon") then
    PartOneCorrect = true
end

if PartPath.BrickColor == BrickColor.new("Really blue") or PartPath.BrickColor == BrickColor.new("Bright blue")  or PartPath.BrickColor == BrickColor.new("Electric blue") then
    PartTwoCorrect = true
end

if PartPath.BrickColor == BrickColor.new("Ghost grey") then
    PartThreeCorrect = true
end

if PartOneCorrect == true and PartTwoCorrect == true and PartThreeCorrect == true then
    --Run what code you want to run here
end
Ad

Answer this question