Try replacing what you have by this:
function table.copy(t)
local copiedTable = {}
for key, value in pairs(t) do
if value ~= _G then
copiedTable[key] = value
end
end
return copiedTable
end
function Wrapper.createEnvironment()
local env = table.copy(_G)
env._G = env
setmetatable(env, {
__index = function(_, index)
if index == "source" then
return _G.source
else
return rawget(env, index)
end
end
})
return env
end
The reason this's happening is that MTA is declaring the source variable within the script's original environment. Thus, you need to get the variable's value from the script's original environment which is already defined as _G. Also, environments' meta table have no effect at all as you're giving them the same functionality Lua actually does originally. Besides, you had some issues with table.move I won't say critical but may cause bugs for some maps scripts.