Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to change a gui color upon clicking a button?

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

✓ Accepted answer

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:

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:

local variable, variable2 = 1;

variable gets 1 and variable2 is just nil.

The fix

use the fromRGB constructor function found in the Color3 table:

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

1 comment

0

thanks for the help

This discussion is preserved as it was. New answers, comments, and votes are closed.