Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

attempt to call a Boolean value (1)?

Asked by 3 years ago
Edited 3 years ago

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

1 answer

Log in to vote
0
Answered by 3 years ago

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)
Ad

Answer this question