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

how do i change part color using if statements?

Asked by
mewtify 26
2 years ago

im trying to change the part color everytime you click it. it goes in order of pink, blue, red, green, and then back to pink. i dont know why this wont work? Nothing is in the output.

local click = script.Parent.ClickDetector
partcolor = script.Parent.BrickColor
local sound = script.Parent.Beep

click.MouseClick:connect(function()
    if partcolor == "255, 0, 191" then
        sound:Play()
        partcolor = "0, 0, 255"
    end

    if partcolor == "0, 0, 255" then
        sound:Play()
        partcolor = "255, 0, 0" 
    end

    if partcolor == "255, 0, 0" then
        sound:Play()
        partcolor = "0, 255, 0"
    end

    if partcolor == "0, 255, 0" then
        sound:Play()
        partcolor = "255, 0, 191"           
    end
end)

please help, thank you

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

.BrickColor can't be assigned to a string value, instead you can do a BrickColor.new() value so when you set partcolor, for example on line 8 it could be partcolor = BrickColor.new(0,0,255). The final code would be:

local click = script.Parent.ClickDetector
partcolor = script.Parent.BrickColor
local sound = script.Parent.Beep

click.MouseClick:connect(function()
    if partcolor == BrickColor.new(255, 0, 191) then
        sound:Play()
        partcolor = BrickColor.new(0,0,255)
    end

    if partcolor == BrickColor.new(0, 0, 255) then
        sound:Play()
        partcolor = BrickColor.new(255, 0, 0)
    end

    if partcolor == BrickColor.new(255, 0, 0) then
        sound:Play()
        partcolor = BrickColor.new(0, 255, 0)
    end

    if partcolor == BrickColor.new(0, 255, 0) then
        sound:Play()
        partcolor = BrickColor.new(255, 0, 191)           
    end
end)

I hope this helped! If this did solve your problem might you select this as the answer, Thanks!

Ad

Answer this question