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

attempt to call a Boolean value (1)?

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

✓ Accepted answer

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)

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