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

How do I CHECK the BrickColor of a part?

Asked by 6 years ago

I'm trying to check the BrickColor of a part and all I can think of to check the Brickcolor is

if  HoleA.BrickColor.red then 
    print "hello world"
end 

*HoleA is a variable of the part I want to check

The error I get when Is "red is not a valid member of BrickColor"

How do I check the BrickColor of a part

2 answers

Log in to vote
2
Answered by
yHasteeD 1819 Moderation Voter
6 years ago
Edited 6 years ago

Use if ... == ... then ... end for check arguments.

You can see of Conditional Statements here in wiki: Conditional Statements in Lua

Conditional statements allow your script to perform specific actions when specific conditions are met.

Here is a example image: Image

if code script:

if 2 + 3 == 5 then
    print("two plus three is five")
end

There is also the "else"

else image example

else code example:

if 10 > 100 then 
    print("10 is greater than 100") 
else 
    print("10 is less than 100") 
end

There are also things with "elseif" here's an example:

elseif image example

elseif code example:

if 10 > 100 then 
    print("10 is greater than 100") 
elseif 10 > 50 then 
    print("10 is greater than 50") 
elseif 10 < 100 then    
    print("10 is less than 100") 
end

All of the above is on the wiki

It is advisable to read the wiki, because there are many other examples.

How to detect color?

local brick = game.Workspace.Part -- Brick location.
if brick.BrickColor == BrickColor.new("Alder") then -- Check if brick color is Alder if is Color in Alder then...
    print("Hello") -- print hello in output
end

How to set color?

local brick = game.Workspace.Part -- Brick location.
brick.BrickColor = BrickColor.new("Alder") -- Set color to brick.

you can see of BrickColor Code's in wiki:

BrickColor Code's - Wiki

You can see of BrickColor in wiki:

BrickColor - Wiki

Hope it helped :)

1
() aren't compulsory. `print "Hello World!"` works just fine. zafiruatest 75 — 6y
0
edited now yHasteeD 1819 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You could do it like this

local HoleA= game.Workspace.Part
HoleA.BrickColor = BrickColor.new("Alder")

if HoleA.BrickColor == BrickColor.new("Alder") then
    print("Subscribe to Pewdiepie")
end
0
thanks! Alex_Capone 0 — 6y
0
Explain the script. yHasteeD 1819 — 6y
0
no u yHasteeD greatneil80 2647 — 6y

Answer this question