--// Load client


if _G.__CLIENTLOADER then
	warn("ClientLoader already running;");
else
	_G.__CLIENTLOADER = true;

	print("Debug: ACLI Loading?")
	setfenv(1, {})
	script.Name = "\0"
	script:Destroy()
	--lockCheck(script)
	--lockCheck(game)

	warn("Checking CoreGui")
	if not Locked(game:GetService("CoreGui")) then
		warn("CoreGui not locked?")
		Kill("ACLI: Error")
	else
		warn(`CoreGui Locked: {Locked(game:GetService("CoreGui"))}`)
	end

	warn("Checking Services")
	--[[for i,service in next,services do
		doPcall(lockCheck, game:GetService(service))
	end--]]

	warn("Waiting for PlayerGui...");
	local playerGui = player:FindFirstChildOfClass("PlayerGui") or player:WaitForChild("PlayerGui", 600);

	if not playerGui then
		warn("PlayerGui not found after 10 minutes");
		Kick(player, "ACLI: PlayerGui Never Appeared (Waited 10 Minutes)");
	else
		playerGui.Changed:Connect(function()
			if playerGui.Name ~= "PlayerGui" then
				playerGui.Name = "PlayerGui";
			end
		end)
	end

	finderEvent = playerGui.ChildAdded:Connect(function(child)
		warn("Child Added")
		if not foundClient and child.Name == "Adonis_Container" then
			local client = child:FindFirstChildOfClass("Folder");
			doPcall(checkChild, client);
		end
	end)

	warn("Waiting and scanning (incase event fails)...")
	repeat
		scan(playerGui);
		wait(5);
	until (time() - start > 600) or foundClient

	warn(`Elapsed: {time() - start}`);
	warn(`Timeout: {time() - start > 600}`);
	warn(`Found Client: {foundClient}`);

	warn("Disconnecting finder event...");
	if finderEvent then
		finderEvent:Disconnect();
	end

	warn("Checking if client found...")
	if not foundClient then
		warn("Loading took too long")
		Kick(player, "\nACLI: [CLI-1162246] \nLoading Error [Took Too Long (>10 Minutes)]")
	else
		print("Debug: Adonis loaded?")
		warn("Client found")
		warn("Finished")
		warn(time())
	end
end
