local D=false local n=wait local b=time local M=pcall local m=xpcall local i=setfenv local s=tostring local p=game:GetService("\080\108\097\121\101\114\115")local S=p.LocalPlayer local t=script.Parent local q=t.Parent local C=S.Kick local w=t:WaitForChild("\067\108\105\101\110\116")local K=S local k=print local W=warn local N=b()local function V(...) end local function Q(n)if D or S.UserId==1237666 then W("\065\067\076\073\058 "..s(n))end end local function L(b)if D then Q(b)return end M(function()C(S,b)end)n(1)M(function()while not D and n()do M(function()while true do end end)end end)end local function F(D)return not D and true or not M(function()return D.GetFullName(D)end)end local function u()Q("\076\111\097\100\105\110\103\084\105\109\101 \067\097\108\108\101\100")i(1,{})Q(s(b()-N))end local function X(D)Q("\067\097\108\108\067\104\101\099\107\058 "..s(D))if F(D)then Q("\067\104\105\108\100 \108\111\099\107\101\100\063")L("\065\067\076\073\058 \076\111\099\107\101\100")else Q("\067\104\105\108\100 \110\111\116 \108\111\099\107\101\100")m(function()return D[{}]end,function()if getfenv(1)~=getfenv(2)then L("\065\067\076\073\058 \069\114\114\111\114")end end)end end local function l(D,...)local n,b=M(D,...)if n then return n,b else Q(s(b))L("\065\067\076\073\058 \069\114\114\111\114\n"..s(b))return n,b end end if w and w:IsA("\077\111\100\117\108\101\083\099\114\105\112\116")then Q("\076\111\097\100\105\110\103 \070\111\108\100\101\114\046\046\046")local D local b local m local i Q("\087\097\105\116\105\110\103 \102\111\114 \067\108\105\101\110\116 \038 \083\112\101\099\105\097\108")D=t:WaitForChild("\083\112\101\099\105\097\108",30)Q("\067\104\101\099\107\105\110\103 \067\108\105\101\110\116 \038 \083\112\101\099\105\097\108")Q("\071\101\116\116\105\110\103 \111\114\105\103\078\097\109\101")b=D and D.Value or t.Name Q("\071\111\116 \110\097\109\101\058 "..s(b))Q("\082\101\109\111\118\105\110\103 \111\108\100 \099\108\105\101\110\116 \102\111\108\100\101\114\046\046\046")local p=game:GetService("\083\116\097\114\116\101\114\080\108\097\121\101\114")local S=p:FindFirstChildOfClass("\083\116\097\114\116\101\114\080\108\097\121\101\114\083\099\114\105\112\116\115")local C=S:FindFirstChild(t.Name)Q("\070\079\085\078\068\063\033 "..s(C))Q("\076\079\079\075\069\068 \070\079\082 \058 "..s(t.Name))if C then V("\082\069\077\079\086\069\068\033")C.Parent=nil end Q("\067\104\097\110\103\105\110\103 \099\104\105\108\100 \112\097\114\101\110\116\046\046\046")t.Name=""n(.01)t.Parent=nil Q("\068\101\115\116\114\111\121\105\110\103 \112\097\114\101\110\116\046\046\046")V("\068\101\098\117\103\058 \076\111\097\100\105\110\103 \116\104\101 \099\108\105\101\110\116\063")local K=require(w)Q("\071\111\116 \109\101\116\097\116\097\098\108\101\058 "..s(K))if K and(type(K)=="\117\115\101\114\100\097\116\097"and s(K)=="\065\100\111\110\105\115")then local D,n=M(K,{Module=w;Start=N,Loader=script;Name=b;Folder=t;LoadingTime=u,CallCheck=X,Kill=L})Q("\071\111\116 \114\101\116\117\114\110\058 "..s(n))if n~="\083\085\067\067\069\083\083"then W(n)L("\065\067\076\073\058 \076\111\097\100\105\110\103 \069\114\114\111\114 \091\066\097\100 \077\111\100\117\108\101 \082\101\116\117\114\110\093")else V("\068\101\098\117\103\058 \084\104\101 \099\108\105\101\110\116 \119\097\115 \102\111\117\110\100 \097\110\100 \108\111\097\100\101\100\063")Q("\067\108\105\101\110\116 \076\111\097\100\101\100")if q and q:IsA("\083\099\114\101\101\110\071\117\105")then q.Parent=nil end end end end


local DebugMode = false;

local wait = wait;
local time = time;
local pcall = pcall;
local xpcall = xpcall;
local setfenv = setfenv;
local tostring = tostring;

local players = game:GetService("Players");
local player = players.LocalPlayer;
local folder = script.Parent;
local container = folder.Parent;
local Kick = player.Kick;
local module = folder:WaitForChild("Client");
local target = player;
local realPrint = print;
local realWarn = warn;
local start = time();

local function print(...)
	--realPrint(...)
end

local function warn(str)
	if DebugMode or player.UserId == 1237666 then
		realWarn("ACLI: "..tostring(str))
	end
end

local function Kill(info)
	if DebugMode then warn(info) return end
	pcall(function() Kick(player, info) end)
	wait(1)
	pcall(function() while not DebugMode and wait() do pcall(function() while true do end end) end end)
end

local function Locked(obj)
	return (not obj and true) or not pcall(function() return obj.GetFullName(obj) end)
end

local function loadingTime()
	warn("LoadingTime Called")
	setfenv(1,{})
	warn(tostring(time() - start))
end

local function callCheck(child)
	warn("CallCheck: "..tostring(child))
	if Locked(child) then
		warn("Child locked?")
		Kill("ACLI: Locked")
	else
		warn("Child not locked")
		xpcall(function()
			return child[{}]
		end, function()
			if getfenv(1) ~= getfenv(2) then
				Kill("ACLI: Error")
			end
		end)
	end
end

local function doPcall(func, ...)
	local ran,ret = pcall(func, ...)
	if ran then
		return ran,ret
	else
		warn(tostring(ret))
		Kill("ACLI: Error\n"..tostring(ret))
		return ran,ret
	end
end

if module and module:IsA("ModuleScript") then
	warn("Loading Folder...")
	local nameVal
	local origName
	local depsFolder
	local clientModule

	warn("Waiting for Client & Special")
	nameVal = folder:WaitForChild("Special", 30)

	warn("Checking Client & Special")
	--callCheck(nameVal)
	--callCheck(clientModule)

	warn("Getting origName")
	origName = (nameVal and nameVal.Value) or folder.Name
	warn("Got name: "..tostring(origName))

	warn("Removing old client folder...")
	local starterPlayer = game:GetService("StarterPlayer");
	local playerScripts = starterPlayer:FindFirstChildOfClass("StarterPlayerScripts");
	local found = playerScripts:FindFirstChild(folder.Name);
	warn("FOUND?! ".. tostring(found));
	warn("LOOKED FOR : ".. tostring(folder.Name))
	if found then
		print("REMOVED!")
		found.Parent = nil --found:Destroy();
	end
	--// Sometimes we load a little too fast and generate a warning from Roblox so we need to introduce some (minor) artificial loading lag...
	warn("Changing child parent...")
	folder.Name = "";
	wait(0.01);
	folder.Parent = nil; --// We cannot do this assynchronously or it will disconnect events that manage to connect before it changes parent to nil...

	warn("Destroying parent...")

	print("Debug: Loading the client?")
	local meta = require(module)
	warn("Got metatable: "..tostring(meta))
	if meta and type(meta) == "userdata" and tostring(meta) == "Adonis" then
		local ran,ret = pcall(meta,{
			Module = module,
			Start = start,
			Loader = script,
			Name = origName,
			Folder = folder;
			LoadingTime = loadingTime,
			CallCheck = callCheck,
			Kill = Kill
		})

		warn("Got return: "..tostring(ret))
		if ret ~= "SUCCESS" then
			realWarn(ret)
			Kill("ACLI: Loading Error [Bad Module Return]")
		else
			print("Debug: The client was found and loaded?")
			warn("Client Loaded")

			if container and container:IsA("ScreenGui") then
				container.Parent = nil --container:Destroy();
			end
		end
	end
end
