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

Weird Error with BackgroundColor3?

Asked by 3 years ago
Edited 3 years ago

So I just tried to make a activate/deactivate button with changing their color (white if deactivated, red if activated). My code:

local Button = Instance.new("TextButton")
local ButtonActivated = false
local ActivatedColor = Color3.fromRGB(170, 0, 0)
local DefaultColor = Color3.fromRGB(255, 255, 255)

Button.MouseButton1Click:Connect(function()
    if buttonActivated == false then
        Button.BackgroundColor3 = ActivatedColor
    else
        Button.BackgroundColor3 = DefaultColor
    end
    if ButtonActivated == false then
        -- Activating...
    else
        -- Deactivating...
    end
end)

And it gives the following error:

Players.Hello1502HD.PlayerGui.Script:8: attempt to index function with 'BackgroundColor3'

I can't understand that.

Thx for reading and maybe helping! :)

0
Are you sure Fly is a GuiObject and not a function? cegberry 432 — 3y

1 answer

Log in to vote
0
Answered by
Tabrix 2
3 years ago
Edited 3 years ago
local Button = Instance.new("TextButton")
local ButtonActivated = false
local ActivatedColor = #PUTCOLORSHERE
local DefaultColor = Button.BackgroundColor3

Button.MouseButton1Click:Connect(function()
    if buttonActivated == false then
        Button.BackgroundColor3 = Color3.new(ActivatedColor)
    buttonActivated = true
    elseif buttonActivated == true then
        Button.BackgroundColor3 = Color3.new(DefaultColor)
    buttonActivated = false
    end
end)

the thing is you're trying to relate nothing, and an object to the color you want to put, and not colors

example, you want to have some coffee, but you dont even get a cup, instead, you have a bottle.

0
oh sry i just made an copy paste error... I got this in my script already. Hello1502HD 5 — 3y
Ad

Answer this question