Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why Comparing 2 BrickColors is not working?

local colorsTheme = {"Lime green", "Really red", "Lilac"}

local theme1 = workspace.Theme1
local remote1 = workspace.Remote1
local click1 = workspace.Remote1.ClickDetector

click1.MouseClick:Connect(function(hit)
	remote1.BrickColor = BrickColor.new(colorsTheme[math.random(1, #colorsTheme)])
end)

if workspace.Remote1.BrickColor == workspace.Theme1.BrickColor then
	print("Player 1 Won")
end

So Basically, there are only 3 avaiable colors that can be changed of the brick, when Remote Has The Same BrickColor as the theme, then it prints "You Win" but it doesn't work, i keep checking if colors are the same and they are, but there is no print

1 answer

✓ Accepted answer

This is because the conditional statement is ran immediately as the program is executed, and it will not run again. To solve your issue, nest this statement within a Changed signal to call upon it whenever the partnering Instance's colour changes:

local colorsTheme = {"Lime green", "Really red", "Lilac"}

local theme1 = workspace.Theme1
local remote1 = workspace.Remote1
local click1 = remote1.ClickDetector

click1.MouseClick:Connect(function(PlayerClicked)
    remote1.BrickColor = BrickColor.new(colorsTheme[math.random(1, #colorsTheme)])
end)

remote1:GetPropertyChangedSignal("BrickColor"):Connect(function()
	if (remote1.BrickColor == theme1.BrickColor) then
		print("Player 1 Won")
	end
end)

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