What I want is to have the line:

repeat wait() until _G.engyn_s _G.engyn_s()

-at the beginning of the script and load in all the functions below within the script to a table. So far, it only works when the functions are above the repeat block but how can I make it so that I can allow the repeat block to be placed at the top of the script and still be able to load all functions within it?

Script Server

_G[ROOT.Name:lower() .. "_s"] = function(...)
	local Documents = ROOT_LIB.Documents;

	local env = getfenv(2);

	local App = {
		Environment = {
			out = function(...)local info = {...};for i, v in pairs(info) do 		print("Engyn("..env["script"]:GetFullName()..") :: "..tostring(v));end end;
			include = coroutine.wrap(function(...)
				local function getDoc(id)
					return Documents[id];
				end

				local function loadDoc(doc)
					for i, v in pairs(doc.Environment) do
						if (type(v) == "function") then
							if (not env[i]) then
								env[i] = v;
							end
						end
					end
				end

				for _, id in pairs({...}) do
					local doc = getDoc(id);
					if (doc) then
						loadDoc(doc);
					else
						if (not getDoc(id)) then
							repeat
								wait()
							until getDoc(id);
						else
							return true;
						end
					end
				end
			end);
		};
	}

	local Meta = {
		__index = {
			init = function(this, env)
				--Transfer all functions to environment
				for i, v in pairs(env) do
					if (type(v) == "function") then
						this.Environment[i] = v;
					end
				end
			end;
		};
		__call = function(this, args)
			
		end;
	}

	App.New = function(env, ...)
		local app = setmetatable(App, Meta);
		app.script = env["script"];
		
		app:init(env);
		app({...});
		return app;
	end
	
	Documents[env["script"].Name] = App.New(env, ...);

	for i, v in pairs(App.Environment) do
		env[i] = v;
	end

	return Documents[env["script"].Name];
end

Script a

repeat wait() until _G.engyn_s _G.engyn_s();

include("b");

sayHi();

Script b

function sayHi()
	print("Hi!");
end

repeat wait() until _G.engyn_s _G.engyn_s();