Still have questions? Join our Discord server and get real time help.
Log in to vote

How to change a gui color upon clicking a button?

Asked by 3 months 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


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
Answered by
incapaxx 3361 Badge of Merit Moderation Voter Community Moderator
3 months ago
Edited 3 months 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);

thanks for the help MPforfun 32 — 3mo

Answer this question