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

Im trying to make it so the button wont work if it's a certain color?

Asked by 2 years ago

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)

3 answers

Log in to vote
0
Answered by 2 years ago

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)

0
Please press the "Lua" button and paste your code inside it to easily format it so we can understand it. Bigmancozmo 7 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

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?

Log in to vote
0
Answered by 2 years ago

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)

Answer this question