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 4 years ago
Edited 4 years ago

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

01local Button = Instance.new("TextButton")
02local ButtonActivated = false
03local ActivatedColor = Color3.fromRGB(170, 0, 0)
04local DefaultColor = Color3.fromRGB(255, 255, 255)
05 
06Button.MouseButton1Click:Connect(function()
07    if buttonActivated == false then
08        Button.BackgroundColor3 = ActivatedColor
09    else
10        Button.BackgroundColor3 = DefaultColor
11    end
12    if ButtonActivated == false then
13        -- Activating...
14    else
15        -- Deactivating...
16    end
17end)

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 — 4y

1 answer

Log in to vote
0
Answered by
Tabrix 2
4 years ago
Edited 4 years ago
01local Button = Instance.new("TextButton")
02local ButtonActivated = false
03local ActivatedColor = #PUTCOLORSHERE
04local DefaultColor = Button.BackgroundColor3
05 
06Button.MouseButton1Click:Connect(function()
07    if buttonActivated == false then
08        Button.BackgroundColor3 = Color3.new(ActivatedColor)
09    buttonActivated = true
10    elseif buttonActivated == true then
11        Button.BackgroundColor3 = Color3.new(DefaultColor)
12    buttonActivated = false
13    end
14end)

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 — 4y
Ad

Answer this question