Creating a UI Color changing Setting

Currently in my game I have over 100 text lables, text buttons, frames etc… I was trying to find a way to have all of those background colors switch to whatever the user selects for example if they want red they can change it to red.

Currently they are all set to a green color. Is there a way where I can get them to change without adding individual scripts into each and every single UI element?

Thank You,
Madd

Could make table of all of them and then loop though and set the color, something like this:

local guiFolder = game:GetService("StarterGui").GUI

for _, v in pairs(guiFolder:GetChildren()) do
    -- set the color of v
end

If you want to select a color just wrap it in a function and pass it as an argument

I tried running this and it wouldn’t work. Just to be clear the rgb color that I want to change is 0,77,0. So would I set v to that?

No that’s not at all what you would do. You need to set v.BackgroundColor equal to Color3.fromRGB(0,77,0). The color is a property of the gui, so we need to access it with dot notation, and we need to call Color3.fromRGB instead of Color3.new because Color3 has a range from 0-1 instead of 0-255.

Ok, so I did something like this:

local uiElements = {}
local selectedColor = Color3.fromRGB(0, 77, 0) -- the color the user selected

for _, child in pairs(game:GetService("StarterGui").GameUI:GetDescendants()) do
	if child.BackgroundColor3 == selectedColor then
		table.insert(uiElements, child)
	end
end

for _, element in pairs(uiElements) do
	element.BackgroundColor3 = Color3.fromRGB(176, 225, 245) -- the new color
end

But it yielded an error that it couldn’t find background color in a UICorner and of course it wouldn’t be in a UI Corner. So is there a way to filter it so that when it searches it only looks through text labels, frames, buttons etc…

local uiElements = {}
local selectedColor = Color3.fromRGB(0, 77, 0) -- the color the user selected

for _, child in pairs(game:GetService("StarterGui").GameUI:GetDescendants()) do
	if child.BackgroundColor3 and child.BackgroundColor3 == selectedColor then
		table.insert(uiElements, child)
	end
end

for _, element in pairs(uiElements) do
	element.BackgroundColor3 = Color3.fromRGB(176, 225, 245) -- the new color
end

Thank you so much I tried this and it worked perfectly

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.