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

This "if" statement isn't working?

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

p1 = game.Workspace.p1
b = math.random(1, 2)

print(b)

if b == 1 then
	color = "white"
end

if color == "white" and
	p1.BrickColor == "White" then
		p1.Transparency=0 else
		p1.Transparency=1

if b == 2 then
	color = "red"
end

if color == "red" and
	p1.BrickColor == "Bright red" then
		p1.Transparency=0 else
		p1.Transparency=1

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

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:

p1 = game.Workspace.p1
math.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.
wait() --Slight delay
b = math.random(1, 2)

print(b)

if b == 1 then 
    color = "White"
elseif b == 2 then --elseif check to see if b ~=something,  but does it == something else.
	color = "Bright red"
end

if color == "White" then
	p1.BrickColor = BrickColor.new(color) --you can replace color with any of the brick colors, "Bright purple", "Bright green" etc.
elseif color == "Bright red" then
	p1.BrickColor = BrickColor.new(color)
	
end

--Note: It may take a few tries but the color will eventually be different.

1 comment

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"

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