Hello, I have a problem with my script. I have three different parts every second they change their color from red to green with math.random. Basiclly its a color cycle. So my problem is that have a part and its transparency is 1.
if part1.BrickColor = Brickcolor.new("Dark Green") then
click.MouseClick:Connect(function()(
Number1.Transparency = 0
end)
end
thats what I want to happen. When the button is red then nothing happens - thats ok. When it gets green and I click on it - it works, but when it hits green and then I wait till it hits red again i click and it works as well - thats bad. I know it might be complicated to understand... Any solutions? whole Script:
Number1 = script.Parent.Number1
part1 = script.Parent.part1
part2 = script.Parent.part2
part3 = script.Parent.part3
click = script.Parent.part1.ClickDetector
-- Properties
Number1.Transparency = 1
part1.BrickColor = BrickColor.new("Really red")
part2.BrickColor = BrickColor.new("Really red")
part3.BrickColor = BrickColor.new("Really red")
--Code
while true do
RandomPart = math.random(1,3)
wait(1)
if RandomPart == 1 then
part1.BrickColor = BrickColor.new("Dark green")
part2.BrickColor = BrickColor.new("Really red")
part3.BrickColor = BrickColor.new("Really red")
part4.BrickColor = BrickColor.new("Really red")
part5.BrickColor = BrickColor.new("Really red")
part6.BrickColor = BrickColor.new("Really red")
part7.BrickColor = BrickColor.new("Really red")
part8.BrickColor = BrickColor.new("Really red")
part9.BrickColor = BrickColor.new("Really red")
elseif RandomPart == 2 then
part1.BrickColor = BrickColor.new("Really red")
part2.BrickColor = BrickColor.new("Dark green")
part3.BrickColor = BrickColor.new("Really red")
part4.BrickColor = BrickColor.new("Really red")
part5.BrickColor = BrickColor.new("Really red")
part6.BrickColor = BrickColor.new("Really red")
part7.BrickColor = BrickColor.new("Really red")
part8.BrickColor = BrickColor.new("Really red")
part9.BrickColor = BrickColor.new("Really red")
elseif RandomPart == 3 then
part1.BrickColor = BrickColor.new("Really red")
part2.BrickColor = BrickColor.new("Really red")
part3.BrickColor = BrickColor.new("Dark green")
wait(1)
end
if part1.BrickColor == BrickColor.new("Dark green") then
click.MouseClick:Connect(function()
Number1.Transparency = 0
end)
end
end
Thank you.

2 comments
{} doesn't make a value a table. {} is the table constructor. In fact, all Lua datatypes but tables are immutable.
That is what I meant by “{} make a value a table”, though I do see how that could be confusing. I edited it and it should be fixed.