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?
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.
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