I wrote this block of code and it ran fine
function win_condition() local b1 = game.Workspace.b1.BrickColor.Name local b2 = game.Workspace.b2.BrickColor.Name local b3 = game.Workspace.b3.BrickColor.Name local bg = "Bright green" if b1 == bg and b2 == bg and b3 == bg then print("bingo!") end end script.Parent.ClickDetector.MouseClick:Connect(function() script.Parent.BrickColor = BrickColor.new("Bright green") win_condition() end)
However, when I tried to make the part change to different colors depending on the team of the player (who clicked), a weird problem came up.
function win_condition() local b1 = game.Workspace.b1.BrickColor.Name local b2 = game.Workspace.b2.BrickColor.Name local b3 = game.Workspace.b3.BrickColor.Name local bg = "Bright green" if b1 == bg and b2 == bg and b3 == bg then print("bingo!") end end ** script.Parent.ClickDetector.MouseClick:Connect(function(player) if player.Team == game.Teams.circles then script.Parent.BrickColor = BrickColor.new("Bright green") elseif player.Team == game.Teams.crosses then script.Parent.BrickColor = BrickColor.new("Bright red") end** win_condition() end)
The code still ran but the function "win_condition()" no longer worked properly. It would only print "bingo!" when each part was clicked TWICE.
When all 3 parts were changed to Bright green, it wouldn't react. However, if I clicked each part a second time, the function would run.
Sorry if I worded this strangely Many thanks
While this may not be the solution, I noticed that your win_condition() function is only checking for the bright green color, not the bright red color. Try checking for the second color as well.
Another thing I noticed about your code is the way you check teams. Usually, a better way to check that is more foolproof is:
if player.TeamColor == Teams.circles.TeamColor then --Code end
I hope this helped!