Making exceptions for getting descendants

I’m currently running into a problem.
I’m trying to create a light/dark theme for a gui. I’ve chosen to do it this way because the gui has many frames and i don’t feel like putting the path of every single one when a user switches to dark/light mode. This is an early concept, if you have any ideas on how to improve this then fire away.

The problem that I’m having is that I’m not sure if there is a feature where you can create exceptions for getting descendants. It would be very useful since the code below changes every single frame’s colour. I’m also storing the colour pallet intimation in folders than can be accessed.

image

local PlayerGui = game:GetService("Players").LocalPlayer.PlayerGui
local ColorPallet = PlayerGui.MacScreen.ColourPallet

for _,v in pairs(PlayerGui.MacScreen.Main:GetDescendants()) do
	if v:IsA("Frame") then
		v.BackgroundColor3 = ColorPallet.DarkMode.Dark.Value
	end
end

If anyone can help it would be greatly appreciated. Even if you have an easier solution.

You could add tags to the exceptions and collectionservice to get a table of them. Such as:

local collectionService = game:GetService("CollectionService")

local exceptions = collectionService:GetTagged("exceptionTag")

for _,v in pairs(PlayerGui.MacScreen.Main:GetDescendants()) do
	if v:IsA("Frame") and not table.find(exceptions, v) then
		v.BackgroundColor3 = ColorPallet.DarkMode.Dark.Value
	end
end

If you want to exclude certain frames but colour everything else you can use attributes, if you add an attribute “Excluded” on each frame that shouldn’t be changed you can do the following:

local PlayerGui = game:GetService("Players").LocalPlayer.PlayerGui
local ColorPallet = PlayerGui.MacScreen.ColourPallet

for _,v in pairs(PlayerGui.MacScreen.Main:GetDescendants()) do
	if v:IsA("Frame") and not v:GetAttribute("Excluded") then
		v.BackgroundColor3 = ColorPallet.DarkMode.Dark.Value
	end
end
1 Like

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