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

How to change a gui color upon clicking a button?

Asked by 5 years ago

ok so i want to have the gui color change upon this button being clicked by the player so they get to choose the color they want the gui to be i have this script inserted into the button on the screen script.Parent.MouseButton1Click:Connect(function()

script.Parent.Parent.Parent.CoinLabel.BackgroundColor3 = 255, 0, 0

end)

this should change it to red but it apears i dont know what im doing and have done something wrong. if you could tell me what i did wrong so i can fix it that would be good. im pretty sure its the part where its BackgroundColor3 = 255, 0 , 0 but idk what to add to that to make it work.

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

The issue is that you are trying to assign BackgroundColor3 to 255. Remember that in multiple assignment, additional results get discarded.

When there are more expressions than variables:

lua local variable = 1, 2;

variable is assigned to 1 and 2 is silently discarded.

A similar thing happens when there are more variables than expressions:

lua local variable, variable2 = 1;

variable gets 1 and variable2 is just nil.

The fix

use the fromRGB constructor function found in the Color3 table:

lua script.Parent.Parent.Parent.CoinLabel.BackgroundColor3 = Color3.fromRGB(255, 0, 0);

0
thanks for the help MPforfun 91 — 5y
Ad

Answer this question