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

This "if" statement isn't working?

Asked by 9 years ago

Hi, so here is my script with an if statement in it:

01p1 = game.Workspace.p1
02b = math.random(1, 2)
03 
04print(b)
05 
06if b == 1 then
07    color = "white"
08end
09 
10if color == "white" and
11    p1.BrickColor == "White" then
12        p1.Transparency=0 else
13        p1.Transparency=1
14 
15if b == 2 then
View all 22 lines...

Even when b is "white" and p1's Brick color is "White," p1's transparency is 1. Same goes with red.

Anyone know why this isn't working properly?

1 answer

Log in to vote
0
Answered by 9 years ago

So I'm assuming you want to change the bricks color depending on if b is 1 or, 2. With that, I redid your script to:

01p1 = game.Workspace.p1
02math.randomseed(tick()) --This makes sure that the math.random will never stay as just one or just two, if you put it before the math.random it will never always be one color.
03wait() --Slight delay
04b = math.random(1, 2)
05 
06print(b)
07 
08if b == 1 then
09    color = "White"
10elseif b == 2 then --elseif check to see if b ~=something,  but does it == something else.
11    color = "Bright red"
12end
13 
14if color == "White" then
15    p1.BrickColor = BrickColor.new(color) --you can replace color with any of the brick colors, "Bright purple", "Bright green" etc.
View all 21 lines...
0
While I appreciate you taking the time to rewrite the script, I was actually trying to change the transparency of parts depending on their BrickColor and the random "b" DrCylonide 158 — 9y
Ad

Answer this question