return function()local n,P,x,r,N,l,e,z,h,t,p,T,X,u,O,G,a,Z,v,S,C,M,I,g,m,U,y,Y,s,o,E,B,L,j,q,K,W,k,D,d,J,V,A,H,c,i,Q,R,b,f,w,F,nR,PR,xR,rR,NR,lR,eR,zR,hR=_G,game,script,getfenv,setfenv,workspace,getmetatable,setmetatable,loadstring,coroutine,rawequal,typeof,print,math,warn,error,pcall,pcall,xpcall,select,rawset,rawget,ipairs,pairs,next,Rect,Axes,os,tick,Faces,unpack,string,Color3,newproxy,tostring,tonumber,Instance,TweenInfo,BrickColor,NumberRange,ColorSequence,NumberSequence,ColorSequenceKeypoint,NumberSequenceKeypoint,PhysicalProperties,Region3int16,Vector3int16,elapsedTime,require,table,type,wait,Enum,UDim,UDim2,Vector2,Vector3,Region3,CFrame,Ray,delay local tR=x local pR=service local TR=client local XR,uR,OR,GR,aR,ZR,vR,SR local function CR()ZR=TR.UI XR=TR.Anti uR=TR.Core vR=TR.Variables OR=TR.Functions GR=TR.Process aR=TR.Remote SR=TR.Deps end;(r()).client=nil;(r()).service=nil;(r()).script=nil TR.UI={Init=CR,GetHolder=function()if ZR.Holder and ZR.Holder.Parent==pR.PlayerGui then return ZR.Holder else Z(function()if ZR.Holder then ZR.Holder:Destroy()end end)local n=W.new("\083\099\114\101\101\110\071\117\105")n.Name=OR.GetRandom()n.Parent=pR.PlayerGui ZR.Holder=n return ZR.Holder end end;Prepare=function(n)if true then return n end local P=ZR.Get(n,false,true)if n:IsA("\083\099\114\101\101\110\071\117\105")or n:IsA("\071\117\105\077\097\105\110")then local x=W.new("\084\101\120\116\076\097\098\101\108")x.BackgroundTransparency=1 x.Size=xR.new(1,0,1,0)x.Name=n.Name x.Active=true x.Text=""for n,P in m,n:GetChildren()do P.Parent=x end if P then P:Register(x)end n:Destroy()return x else return n end end;LoadModule=function(n,P,x)local r,l=Z(b,n)local e=GetEnv(x)local z=P or{}e.script=n e.client=pR.CloneTable(TR)e.service=pR.CloneTable(pR)e.service.Threads=pR.CloneTable(pR.Threads)for n,P in m,e.client do if w(P)=="\116\097\098\108\101"and(n~="\086\097\114\105\097\098\108\101\115"and n~="\072\097\110\100\108\101\114\115")then e.client[n]=pR.CloneTable(P)end end if r then local P={pR.TrackTask("\085\073\058 "..n:GetFullName(),N(l,e),z)}local x=P[1]if x then return E(P,2)else O("\069\114\114\111\114 \119\104\105\108\101 \114\117\110\110\105\110\103 \109\111\100\117\108\101 "..n.Name,q(P[2]))TR.LogError("\069\114\114\111\114 \108\111\097\100\105\110\103 "..(q(n)..(" - "..q(P[2]))))end else O("\069\114\114\111\114 \119\104\105\108\101 \108\111\097\100\105\110\103 \109\111\100\117\108\101 "..n.Name,q(l))end end,GetNew=function(n,P)local x={}local r={}local N={}local l=W.new("\070\111\108\100\101\114")local e function e(n,P,r)local N=(r or 11)-1 local l=SR.UI:FindFirstChild(n)or SR.UI.Default if l then local r=l:FindFirstChild("\066\097\115\101\095\084\104\101\109\101")local z=r and r.Value local h=r and l:FindFirstChild(P)or SR.UI.Default:FindFirstChild(P)if h then local N=h:FindFirstChild("\067\111\110\102\105\103")f.insert(x,{Theme=n,Folder=l;Name=P,Found=h,Config=N;isModule=h:IsA("\077\111\100\117\108\101\083\099\114\105\112\116")})if N then r=N:FindFirstChild("\066\097\115\101\084\104\101\109\101")or r z=r and r.Value end end if z and N>0 then e(z,P,N)end end end e(n,P)l.Name="\067\111\110\102\105\103"if#x>0 then for n,P in m,x do if P.Config then for n,P in m,P.Config:GetChildren()do if not r[P.Name]then r[P.Name]=P end end end end for n,P in m,r do(P:Clone()).Parent=l end if x[1].isModule then return x[1].Found,x[1].Folder,l elseif not r.Code then for n,P in m,x do if P.isModule then return P.Found,P.Folder,l end end end local n=x[1].Found:Clone()local P=n:FindFirstChild("\067\111\110\102\105\103")if P then P:Destroy()end l.Parent=n return n,x[1].Folder,l end end,Make=function(n,P,x)local r=P or{}local l={Desktop="\068\101\102\097\117\108\116",Mobile="\077\111\098\105\108\105\117\115"}local e=x or uR.Theme or l local z=vR.CustomTheme or pR.IsMobile()and e.Mobile or e.Desktop local h=SR.UI:FindFirstChild(z)or SR.UI.Default local t,p,T=ZR.GetNew(z,n)if t then local P=t:IsA("\077\111\100\117\108\101\083\099\114\105\112\116")local x=t:FindFirstChild("\067\111\110\102\105\103")if P then return ZR.LoadModule(t,r,{script=t})elseif x and(T and T~=true)then local P=T.Code local l=T.AllowMultiple local e=T.CanKeepAlive local z=l and l.Value or true local p,X=ZR.Get(n)if not p or(X and X>0)and z then local l,e=ZR.Register(t)local z={}if h:IsA("\077\111\100\117\108\101\083\099\114\105\112\116")then z.script=h z.gTable=l local n,x=Z(b,h)local e=GetEnv(z)local p={Z(N(x,e),t,l,r)}local T=p[1]local X=p[2]if X~=nil then if w(X)=="\117\115\101\114\100\097\116\097"and XR.GetClassName(X)=="\083\099\114\101\101\110\071\117\105"then P=X:FindFirstChild("\067\111\110\102\105\103")and X.Config:FindFirstChild("\067\111\100\101")or P else return X end end end t.Parent=vR.GUIHolder t.Name=OR.GetRandom()r.gIndex=e r.gTable=l P.Parent=x P.Name=n return ZR.LoadModule(P,r,{script=P;gTable=l;Data=r,GUI=t})end end else X("\071\085\073 "..(q(n).." \110\111\116 \102\111\117\110\100"))end end,Get=function(n,P,x)local r={}local N=0 if n then for l,e in m,TR.GUIs do if e.Name~=P and(e.Object~=P and e~=P)then if w(n)=="\115\116\114\105\110\103"then if e.Name==n then r[l]=e N=N+1 if x then return e end end elseif w(n)=="\117\115\101\114\100\097\116\097"then if pR.RawEqual(e.Object,n)then r[l]=e N=N+1 if x then return e end end elseif w(n)=="\098\111\111\108\101\097\110"and n==true then r[l]=e N=N+1 if x then return e end end end end end if N<1 then return false else return r,N end end,Remove=function(n,P)local x=ZR.Get(n,P)if x then for n,P in m,x do P.Destroy()end end end,Register=function(n,P)local x=OR.GetRandom()local r r={Object=n;Config=n:FindFirstChild("\067\111\110\102\105\103");Name=n.Name;Events={};Class=n.ClassName,Index=x;Active=true;Ready=function()if r.Config then r.Config.Parent=nil end if Z(function()if r.Class=="\083\099\114\101\101\110\071\117\105"or r.Class=="\071\117\105\077\097\105\110"then r.Object.Parent=pR.PlayerGui else r.Object.Parent=ZR.GetHolder()end end)then r.Active=true else O("\083\111\109\101\116\104\105\110\103 \104\097\112\112\101\110\101\100 \119\104\105\108\101 \116\114\121\105\110\103 \116\111 \115\101\116 \116\104\101 \112\097\114\101\110\116 \111\102 "..q(r.Name))O("\077\097\121\098\101 \105\116 \119\097\115 \108\111\099\107\101\100 \040\068\101\115\116\114\111\121\101\100\041\063")r:Destroy()end end,BindEvent=function(n,P)local x=n:connect(P)local N=x.Disconnect local l=r.Events local e=function()N(x)for n,P in m,l do if P.Signal==x then f.remove(l,n)end end end f.insert(l,{Signal=x,Remove=e})return{Disconnect=e;disconnect=e;wait=pR.CheckProperty(x,"\119\097\105\116")and x.wait},x end;ClearEvents=function()for n,P in m,r.Events do P:Remove()end end,Destroy=function()Z(function()if r.CustomDestroy then r.CustomDestroy()else(pR.UnWrap(r.Object)):Destroy()end end)r.Destroyed=true r.Active=false TR.GUIs[x]=nil r.ClearEvents()end;UnRegister=function()TR.GUIs[x]=nil if r.AncestryEvent then r.AncestryEvent:Disconnect()end end;Register=function(n,P)if not P then P=n end P:SetSpecial("\068\101\115\116\114\111\121",r.Destroy)r.Object=pR.Wrap(P)r.Class=P.ClassName if r.AncestryEvent then r.AncestryEvent:Disconnect()end r.AncestryEvent=P.AncestryChanged:Connect(function(n,P)if TR.GUIs[x]then if p(n,r.Object)and(r.Class=="\084\101\120\116\076\097\098\101\108"and P==pR.PlayerGui)then F()r.Object.Parent=ZR.GetHolder()elseif p(n,r.Object)and(P==nil and not r.KeepAlive)then r:Destroy()elseif p(n,r.Object)and P~=nil then r.Active=true TR.GUIs[x]=r end end end)TR.GUIs[x]=r end}if P then for n,P in m,P do r[n]=P end end n.Name=OR.GetRandom()r:Register(n)return r,x end}TR.UI.RegisterGui=TR.UI.Register TR.UI.GetGui=TR.UI.Get TR.UI.PrepareGui=TR.UI.Prepare TR.UI.MakeGui=TR.UI.Make end

return function()
	local _G, game, script, getfenv, setfenv, workspace, 
		getmetatable, setmetatable, loadstring, coroutine, 
		rawequal, typeof, print, math, warn, error,  pcall, 
		pcall, xpcall, select, rawset, rawget, ipairs, pairs, 
		next, Rect, Axes, os, tick, Faces, unpack, string, Color3, 
		newproxy, tostring, tonumber, Instance, TweenInfo, BrickColor, 
		NumberRange, ColorSequence, NumberSequence, ColorSequenceKeypoint, 
		NumberSequenceKeypoint, PhysicalProperties, Region3int16, 
		Vector3int16, elapsedTime, require, table, type, wait, 
		Enum, UDim, UDim2, Vector2, Vector3, Region3, CFrame, Ray, delay = 
		_G, game, script, getfenv, setfenv, workspace, 
		getmetatable, setmetatable, loadstring, coroutine, 
		rawequal, typeof, print, math, warn, error,  pcall, 
		pcall, xpcall, select, rawset, rawget, ipairs, pairs, 
		next, Rect, Axes, os, tick, Faces, unpack, string, Color3, 
		newproxy, tostring, tonumber, Instance, TweenInfo, BrickColor, 
		NumberRange, ColorSequence, NumberSequence, ColorSequenceKeypoint, 
		NumberSequenceKeypoint, PhysicalProperties, Region3int16, 
		Vector3int16, elapsedTime, require, table, type, wait, 
		Enum, UDim, UDim2, Vector2, Vector3, Region3, CFrame, Ray, delay
		
	local script = script
	local service = service
	local client = client
	local Anti, Core, Functions, Process, Remote, UI, Variables, Deps
	local function Init()
		UI = client.UI;
		Anti = client.Anti;
		Core = client.Core;
		Variables = client.Variables
		Functions = client.Functions;
		Process = client.Process;
		Remote = client.Remote;
		Deps = client.Deps;
	end
	
	getfenv().client = nil
	getfenv().service = nil
	getfenv().script = nil
	
	client.UI = {
		Init = Init;
		GetHolder = function()
			if UI.Holder and UI.Holder.Parent == service.PlayerGui then
				return UI.Holder
			else
				pcall(function()if UI.Holder then UI.Holder:Destroy()end end)
				local new=Instance.new'ScreenGui'
				new.Name = Functions.GetRandom()
				new.Parent=service.PlayerGui
				UI.Holder = new
				return UI.Holder
			end
		end;
		
		Prepare = function(gui)
			if true then return gui end	--// Disabled
			
			local gTable = UI.Get(gui,false,true)
			if gui:IsA("ScreenGui") or gui:IsA("GuiMain") then
				local new = Instance.new("TextLabel")
				new.BackgroundTransparency = 1
				new.Size = UDim2.new(1,0,1,0)
				new.Name = gui.Name
				new.Active = true
				new.Text = ""
				
				for ind,child in next,gui:GetChildren()do
					child.Parent = new
				end
				
				if gTable then
					gTable:Register(new)
				end
				
				gui:Destroy()
				
				return new
			else
				return gui
			end
		end;
		
		LoadModule = function(module, data, env)
			local ran,func = pcall(require, module)
			local newEnv = GetEnv(env)
			local data = data or{}
			
			newEnv.script = module
			newEnv.client = service.CloneTable(client)
			newEnv.service = service.CloneTable(service)
			newEnv.service.Threads = service.CloneTable(service.Threads)
			
			for i,v in next,newEnv.client do
				if type(v) == "table" and i ~= "Variables" and i ~= "Handlers" then
					newEnv.client[i] = service.CloneTable(v)
				end
			end
			
			if ran then
				local rets = {service.TrackTask("UI: ".. module:GetFullName(), setfenv(func,newEnv), data)}
				local ran = rets[1]
				if ran then
					return unpack(rets,2)
				else
					warn("Error while running module "..module.Name,tostring(rets[2]))
					client.LogError("Error loading "..tostring(module).." - "..tostring(rets[2]))
				end
			else
				warn("Error while loading module "..module.Name,tostring(func))
			end
		end;
		
		GetNew = function(theme, name)
			local found = {}
			local endConfig = {}
			local endConfValues = {}
			local confFolder = Instance.new("Folder")
			local func
			
			function func(theme, name, depth)
				local depth = (depth or 11) - 1
				local folder = Deps.UI:FindFirstChild(theme) or Deps.UI.Default
				if folder then
					local baseValue = folder:FindFirstChild("Base_Theme")
					local baseTheme = baseValue and baseValue.Value
					local foundGUI = (baseValue and folder:FindFirstChild(name)) or Deps.UI.Default:FindFirstChild(name)
					
					if foundGUI then
						local config = foundGUI:FindFirstChild("Config")
						table.insert(found, {
							Theme = theme;
							Folder = folder;
							Name = name;
							Found = foundGUI;
							Config = config;
							isModule = foundGUI:IsA("ModuleScript");
						})
						
						if config then
							baseValue = config:FindFirstChild("BaseTheme") or baseValue
							baseTheme = baseValue and baseValue.Value
						end
					end
					
					if baseTheme and depth > 0 then
						func(baseTheme, name, depth)
					end
				end
			end
			
			--// Find GUI and all default versions under it
			func(theme, name)
			confFolder.Name = "Config"
			
			if #found > 0 then
				
				--// Combine all configs found in order  to build full config (in order of closest from target gui to furthest)
				for i,v in next,found do
					if v.Config then
						for k,m in next,v.Config:GetChildren() do
							if not endConfig[m.Name] then
								endConfig[m.Name] = m
							end
						end
					end
				end
				
				--// Load all config values into the new Config folder
				for i,v in next,endConfig do
					v:Clone().Parent = confFolder
				end
				
				--// Find next module based theme GUI if code not found or first in sequence is module (in theme)
				if found[1].isModule then
					return found[1].Found, found[1].Folder, confFolder
				elseif not endConfig.Code then
					for i,v in next,found do
						if v.isModule then
							return v.Found, v.Folder, confFolder
						end
					end
				end
				
				--// Get rid of an old Config folder and throw the new combination Config folder in
				local new = found[1].Found:Clone()
				local oldFolder = new:FindFirstChild'Config'
				
				if oldFolder then oldFolder:Destroy() end
				
				confFolder.Parent = new
				
				return new, found[1].Folder, confFolder
			end
		end;
		
		Make = function(name, data, themeData)
			local data = data or {}
			local defaults = {Desktop = "Default"; Mobile = "Mobilius"}
			local themeData = themeData or Core.Theme or defaults
			local theme = Variables.CustomTheme or (service.IsMobile() and themeData.Mobile) or themeData.Desktop
			local folder = Deps.UI:FindFirstChild(theme) or Deps.UI.Default
			local newGui, folder2, foundConf = UI.GetNew(theme, name)
			
			if newGui then
				local isModule = newGui:IsA("ModuleScript")
				local conf = newGui:FindFirstChild("Config")
				
				if isModule then
					return UI.LoadModule(newGui, data, {
						script = newGui;
					})
				elseif conf and foundConf and foundConf ~= true then
					local code = foundConf.Code
					local mult = foundConf.AllowMultiple
					local keep = foundConf.CanKeepAlive
					
					local allowMult = mult and mult.Value or true
					local found, num = UI.Get(name)
						
					if not found or ((num and num>0) and allowMult) then
						local gTable,gIndex = UI.Register(newGui)
						local newEnv = {}
						
						if folder:IsA("ModuleScript") then
							newEnv.script = folder
							newEnv.gTable = gTable 
							local ran,func = pcall(require, folder)
							local newEnv = GetEnv(newEnv)
							local rets = {pcall(setfenv(func,newEnv),newGui, gTable, data)}
							local ran = rets[1]
							local ret = rets[2]
							
							if ret ~= nil then
								if type(ret) == "userdata" and Anti.GetClassName(ret) == "ScreenGui" then
									code = (ret:FindFirstChild("Config") and ret.Config:FindFirstChild("Code")) or code
								else
									return ret
								end
							end
						end
						
						newGui.Parent = Variables.GUIHolder
						newGui.Name = Functions.GetRandom()
						
						data.gIndex = gIndex
						data.gTable = gTable
						
						code.Parent = conf
						code.Name = name
						
						return UI.LoadModule(code, data, {
							script = code;
							gTable = gTable;
							Data = data;
							GUI = newGui;
						})
					end
				end
			else
				print("GUI "..tostring(name).." not found")
			end
		end;
		
		Get = function(obj,ignore,returnOne)
			local found = {}
			local num = 0
			if obj then
				for ind,g in next,client.GUIs do
					if g.Name ~= ignore and g.Object ~= ignore and g ~= ignore then
						if type(obj) == "string" then
							if g.Name == obj then
								found[ind] = g
								num = num+1
								if returnOne then return g end
							end
						elseif type(obj) == "userdata" then
							if service.RawEqual(g.Object, obj) then
								found[ind] = g
								num = num+1
								if returnOne then return g end
							end
						elseif type(obj) == "boolean" and obj == true then
							found[ind] = g
							num = num+1
							if returnOne then return g end
						end
					end
				end
			end
			if num<1 then 
				return false
			else
				return found,num
			end
		end;
		
		Remove = function(name, ignore)
			local gui = UI.Get(name, ignore)
			if gui then
				for i,v in next,gui do
					v.Destroy()
				end
			end
		end;
		
		Register = function(gui, data)
			local gIndex = Functions.GetRandom()
			local gTable;gTable = {
				Object = gui,
				Config = gui:FindFirstChild'Config';
				Name = gui.Name,
				Events = {},
				Class = gui.ClassName,
				Index = gIndex,
				Active = true,
				Ready = function()
					if gTable.Config then gTable.Config.Parent = nil end
					if pcall(function()
						if gTable.Class == "ScreenGui" or gTable.Class == "GuiMain" then
							gTable.Object.Parent = service.PlayerGui
						else
							gTable.Object.Parent = UI.GetHolder()
						end
					end) then
						gTable.Active = true
					else
						warn("Something happened while trying to set the parent of "..tostring(gTable.Name))
						warn'Maybe it was locked (Destroyed)?'
						gTable:Destroy()
					end
				end,
				BindEvent = function(event, func)
					local signal = event:connect(func)
					local origDisc = signal.Disconnect
					local Events = gTable.Events
					local disc = function()
						origDisc(signal)
						for i,v in next, Events do 
							if v.Signal == signal then
								table.remove(Events, i)
							end
						end
					end
					
					table.insert(Events, {
						Signal = signal;
						Remove = disc
					}) 
					
					return {
						Disconnect = disc;
						disconnect = disc;
						wait = service.CheckProperty(signal, "wait") and signal.wait
					}, signal
				end,
				ClearEvents = function()
					for i,v in next,gTable.Events do
						v:Remove()
					end
				end,
				Destroy = function()
					pcall(function()
						if gTable.CustomDestroy then
							gTable.CustomDestroy()
						else
							service.UnWrap(gTable.Object):Destroy()
						end
					end)
					gTable.Destroyed = true
					gTable.Active = false
					client.GUIs[gIndex] = nil
					gTable.ClearEvents()
				end,
				UnRegister = function()
					client.GUIs[gIndex] = nil
					if gTable.AncestryEvent then
						gTable.AncestryEvent:Disconnect()
					end
				end,
				Register = function(tab,new)
					if not new then new=tab end
					
					new:SetSpecial("Destroy", gTable.Destroy)
					gTable.Object = service.Wrap(new)
					gTable.Class = new.ClassName
					
					if gTable.AncestryEvent then 
						gTable.AncestryEvent:Disconnect()
					end
					
					gTable.AncestryEvent = new.AncestryChanged:Connect(function(c, parent)
						if client.GUIs[gIndex] then
							if rawequal(c, gTable.Object) and gTable.Class == "TextLabel" and parent == service.PlayerGui then
								wait()
								gTable.Object.Parent = UI.GetHolder()
							elseif rawequal(c, gTable.Object) and parent == nil and not gTable.KeepAlive then
								gTable:Destroy()
							elseif rawequal(c, gTable.Object) and parent ~= nil then
								gTable.Active = true
								client.GUIs[gIndex] = gTable
							end
						end
					end)
					client.GUIs[gIndex] = gTable
				end
			}
			
			if data then
				for i,v in next,data do
					gTable[i] = v
				end
			end
			
			gui.Name = Functions.GetRandom()
			gTable:Register(gui)
			
			return gTable,gIndex
		end
	}
	
	client.UI.RegisterGui 	= client.UI.Register
	client.UI.GetGui 		= client.UI.Get
	client.UI.PrepareGui 	= client.UI.Prepare
	client.UI.MakeGui 		= client.UI.Make
end
