When this button is clicked, it will do some code depending on what color it was when it was clicked(I will put the code in later) and then change it's color from green to red, or red to green. But, this script wont work as itis right now.
function onClicked() --If the button is green, make it red. if script.Parent.BrickColor == "Bright green" then script.Parent.BrickColor = BrickColorNew "Bright red" --if the button is red, make it green. elseif script.Parent.BrickColor == "Bright green" then script.Parent.BrickColor = BrickColorNew "Bright red" end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
Fixed:
function onClicked() --If the button is green, make it red. if script.Parent.BrickColor == BrickColor.new("Bright green") then script.Parent.BrickColor = BrickColor.new("Bright red") --if the button is red, make it green. elseif script.Parent.BrickColor == BrickColor.new("Bright green") then script.Parent.BrickColor = BrickColor.new("Bright red") end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
Never try to compare 2 different data types (you were comparing a BrickColor to a string).
Two things
1: Your elseif
is ALSO checking if it is Bright green, not Bright red like the comment said.
2: Like ezt12 said, you can't compare brick colors to strings, you have to compare them to other brick colors
Just change the script to so:
function onClicked() --If the button is green, make it red. if script.Parent.BrickColor == BrickColor.new("Bright green") then script.Parent.BrickColor = BrickColor.new("Bright red") --if the button is red, make it green. elseif script.Parent.BrickColor == BrickColor.new("Bright red") then script.Parent.BrickColor = BrickColor.new("Bright green") end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
You wrote the BrickColor.new
Wrongly, here is the corrected script. Scripts are also case sensitive so the new
would also have to be lower case.
function onClicked() --If the button is green, make it red. if script.Parent.BrickColor == "Bright green" then script.Parent.BrickColor = BrickColor.new "Bright red" --if the button is red, make it green. elseif script.Parent.BrickColor == "Bright green" then script.Parent.BrickColor = BrickColor.new "Bright red" end end script.Parent.ClickDetector.MouseClick:connect(onClicked)