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

How do I have an If-statement recognize the current BrickColor?

Asked by 3 years ago

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)
0
it doesn't recognise "Really red" u neew to specify thats its a brickcolor Pitched_mobile 191 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
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)
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

instead of

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

do


if part.BrickColor == BrickColor.new("Really red") then -- execute code end
0
You can also use enum to see the materials a_crazyjester 21 — 3y
0
You can already see what properties are held inside of brickcolor by using brickcolor.new(). ssgmalachi 52 — 3y

Answer this question