so im kinda new to lua just started about 3 weeks ago.Im trying to make the button not work if the buttons color is red. local button = script.Parent local ball = game.Workspace.ball local function click(player) ball.Position = Vector3.new(39.302, 99.514, -23.488) button.BrickColor = BrickColor.Red() wait(5) button.BrickColor = BrickColor.Green() if ball.BrickColor == "red" then ball.Position = ball.Position end end button.ClickDetector.MouseClick:Connect(click)
COMMUNITY QUESTION
Im trying to make it so the button wont work if it's a certain color?
3 answers
my code:
local button = script.Parent local ball = game.Workspace.ball local function click(player) ball.Position = Vector3.new(39.302, 99.514, -23.488) button.BrickColor = BrickColor.Red() wait(5) button.BrickColor = BrickColor.Green() if ball.BrickColor == "red" then ball.Position = ball.Position end end button.ClickDetector.MouseClick:Connect(click)
well if you're using BrickColor you have to put the specific name of the color and the correct capitalization e.g.
if ball.BrickColor == "Really red" then
but i thought you wanted to check the color of the button, not the ball?
I think this is what you want:
local button = script.Parent
local ball = game.Workspace.ball
local function click(player)
local red = Color3.new(255,0,0) -- Color red
local pos = Vector3.new(39.302, 99.514, -23.488)
if button.BackgroundColor3 == red then -- Check if color of button is red
ball.Position = pos
end
button.BackgroundColor3 = red -- Change GUI button to red
wait(5)
button.BackgroundColor3 = Color3.new(0,255,0) -- Change GUI button to green
end
button.MouseButton1Click:Connect(click)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Please press the "Lua" button and paste your code inside it to easily format it so we can understand it.