local function Z(e,a)local function c(Z,e)local a,c=0,Z local M,T=0,e repeat c=c.Parent a=a+1 until c.Parent==playerGui repeat T=T.Parent M=M+1 until T.Parent==playerGui if a==M then for c,T in ipairs(whitelistedClasses)do if T==Z.ClassName then a=c elseif T==e.ClassName then M=c end end end return a<M and Z or e end for e,M in ipairs(e:GetChildren())do if M.ClassName=="\083\099\114\101\101\110\071\117\105"and not _L.Functions.SearchArray(blacklistedGuis,M.Name)then GUI[M.Name:gsub("\037\115\043","")]={Gui=M}Z(M,M)elseif M:IsA("\071\117\105\079\098\106\101\099\116")and a then local e=GUI[a.Name:gsub("\037\115\043","")][M.Name:gsub("\037\115\043","")]if not e or e and c(M,e)==M then GUI[a.Name:gsub("\037\115\043","")][M.Name:gsub("\037\115\043","")]=M end Z(M,a)end end end Z(playerGui)playerGui.ChildAdded:Connect(function(e)if e.ClassName=="\083\099\114\101\101\110\071\117\105"and not _L.Functions.SearchArray(blacklistedGuis,e.Name)then GUI[e.Name:gsub("\037\115\043","")]={Gui=e}Z(e,e)end end)

local function Scan(instance, parent)
	--- Calculates which gui instance is more important (based on dependance and class)
	local function MoreImportant(a, b)
		local aHeight, aCurr = 0, a
		local bHeight, bCurr = 0, b
		repeat  aCurr = aCurr.Parent  aHeight = aHeight + 1  until aCurr.Parent == playerGui
		repeat  bCurr = bCurr.Parent  bHeight = bHeight + 1  until bCurr.Parent == playerGui
		if aHeight == bHeight then
			for i, v in ipairs(whitelistedClasses) do
				if v == a.ClassName then
					aHeight = i
				elseif v == b.ClassName then
					bHeight = i
				end
			end
		end
		return (aHeight < bHeight and a or b)
	end
	
	--- Iterate through gui instance children
	for _, child in ipairs(instance:GetChildren()) do
		if child.ClassName == "ScreenGui" and (not _L.Functions.SearchArray(blacklistedGuis, child.Name)) then
			GUI[child.Name:gsub("%s+", "")] = {Gui = child}
			Scan(child, child)
		elseif child:IsA("GuiObject") and parent then
			local exists = GUI[parent.Name:gsub("%s+", "")][child.Name:gsub("%s+", "")]
			if (not exists) or (exists and MoreImportant(child, exists) == child) then
				GUI[parent.Name:gsub("%s+", "")][child.Name:gsub("%s+", "")] = child
			end
			Scan(child, parent)
		end
	end
end

Scan(playerGui)

playerGui.ChildAdded:Connect(function(child)
	if child.ClassName == "ScreenGui" and (not _L.Functions.SearchArray(blacklistedGuis, child.Name)) then
		GUI[child.Name:gsub("%s+", "")] = {Gui = child}
		Scan(child, child)
	end
end)

