Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Confusing error when trying to set a protected metatable?

Backstory: So I have been trying to break out of Voidacity (oxcool1)'s sandbox so that I can use require to make my code neater and have access to third party scripts. I found this method of overwriting a protected environment and have adjusted it to my needs. However I believe that overwriting the environment has messed up the functions

a = {
archive = {
print = print,
pairs = pairs,``
nil
},
}
a.env = {unpack(a.archive), unpack(a)}

for k, v in pairs(a.env) do
print(k, "=", v)
archive[k] = v
end

a = setmetatable(a, {
	--metatable, yay!
	__index = function ()
		print("Lol?")
	end,
	__newindex = function ()
		print("lol")
	end
})

setfenv(1, a)


Random= require(HereForProtection:))

Error: The error I get when launching this code in the script builder is "Attempt to call global 'require' (a nil value)"

Why is this error occurring and how would I fix it?

1 answer

I hope this will help.

(Excuse my poor excuse for writing, I am not good in English) The first thing is line 8, when you tried to unpack both tables into the single table. This will not produce the result you are looking for, if you want to mash tables together you can use the following

function MashArray(...) --prob not the best thing to use, but it is something
	local function packitin(a, b)
		for x = 1, #b do 
			a[#a + 1] = b[x]
		end 
	end 
		
	
	local args = {...}
	local new = {}
	
	for x = 1, #args do 
		packitin(new, args[x])
	end 

	return new 
end 

Also, you made a whole new environment (setfenv), and looking at your env, it does not have require in it, which it probably why it is saying require not found.

Of course, I could be wrong

This discussion is preserved as it was. New answers, comments, and votes are closed.