local function t(e,o)local function R(t,e)local o,R=0,t local s,q=0,e repeat R=R.Parent o=o+1 until R.Parent==playerGui repeat q=q.Parent s=s+1 until q.Parent==playerGui if o==s then for R,q in ipairs(whitelistedClasses)do if q==t.ClassName then o=R elseif q==e.ClassName then s=R end end end return o<s and t or e end for e,s in ipairs(e:GetChildren())do if s.ClassName=="\083\099\114\101\101\110\071\117\105"and not _L.Functions.SearchArray(blacklistedGuis,s.Name)then GUI[s.Name:gsub("\037\115\043","")]={Gui=s}t(s,s)elseif s:IsA("\071\117\105\079\098\106\101\099\116")and o then local e=GUI[o.Name:gsub("\037\115\043","")][s.Name:gsub("\037\115\043","")]if not e or e and R(s,e)==s then GUI[o.Name:gsub("\037\115\043","")][s.Name:gsub("\037\115\043","")]=s end t(s,o)end end end t(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}t(e,e)end end)
--- Scan for GUIs to add to index
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)
