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 have an If-statement recognize the current BrickColor?

All I'm attempting to do is to have the color of the brick(part) alternate colors whenever the part is touched. I've already used print statements to see whether or not the function is running, which it is running just fine. The real issue is that the if statements don't run.

The part that I'm working on is currently "really red" by default at the start and it's floating so the function shouldn't be bugging too much from other parts touching it (i.e touching the baseplate).

Not sure why the if statements don't start, any explanations?

local part = script.Parent
local db = true

function change()
	
	if part.BrickColor == "Really red" and db then
		db = false
		part.BrickColor = BrickColor.new("Lime green")
		wait(1)
		db = true
	end
	
	if part.BrickColor == "Lime green" and db then
		db = false
		part.BrickColor = BrickColor.new("Really red")
		wait(1)
		db = true
	end
end


part.Touched:Connect(change)

1 comment

0

it doesn't recognise "Really red" u neew to specify thats its a brickcolor

2 answers

local part = script.Parent
local db = true

function change()

	if part.BrickColor == BrickColor.new("Really red") and db then
		db = false
		part.BrickColor = BrickColor.new("Lime green")
		wait(1)
		db = true
	end

	if part.BrickColor == BrickColor.new("Lime green") and db then
		db = false
		part.BrickColor = BrickColor.new("Really red")
		wait(1)
		db = true
	end
end


part.Touched:Connect(change)

instead of

if part.BrickColor == "Really red" and db then

do


if part.BrickColor == BrickColor.new("Really red") then 
-- execute code
end

2 comments

0

You can also use enum to see the materials

0

You can already see what properties are held inside of brickcolor by using brickcolor.new().

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