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

How do I CHECK the BrickColor of a part?

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

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 :)

2 comments

1

() aren't compulsory. print "Hello World!" works just fine.

0

edited now

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

3 comments

0

thanks!

0

Explain the script.

0

no u yHasteeD

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