So I am trying to make a script where when you click the part it it chooses a number from 1 - 5 and applies that number to the Number Value and if the number chosen is 1 the part turn green but if it is equal to anything else it turns red.
if script.Parent.ClickDetector.MouseClick:Connect(game.Workspace.NumVal.Value == math.random(1,5)) then if game.Workspace.NumVal.Value == 1 then script.Parent.BrickColor = BrickColor.new ("Bright green") else script.Parent.BrickColor = BrickColor.new ("Bright red") end end
An event connection runs every time an event fires and can't be put in an if statement like you did. For an event connection, you need to pass in a function because the game doesn't know what to do with what you gave it. (This is what caused the error because you put a boolean where the function is supposed to go.) Also, == tests if something is equivalent to something else, while = is the symbol that you use to set a variable.
script.Parent.ClickDetector.MouseClick:Connect(function() game.Workspace.NumVal.Value = math.random(1,5) if game.Workspace.NumVal.Value == 1 then script.Parent.BrickColor = BrickColor.new ("Bright green") else script.Parent.BrickColor = BrickColor.new ("Bright red") end end)