So I added a pcall to my script, and now it prints out the error outside the env. It says attempt to call a table value, which I assume is a error outside the env
local outputlines = {}
local scriptran = loadstring[[
print("a")
]]
local env = getfenv(scriptran)
local sandbox = setmetatable({
print = function(...)
table.insert(outputlines,(...))
end,
warn = function(...)
table.insert(outputlines,(...))
end,
error = function(...)
table.insert(outputlines,(...))
end,
},{
__index = function(_,var)
return env[var]
end,
})
setfenv(scriptran,sandbox)
local _, errorMsg: string = pcall(sandbox)
if errorMsg then
print(errorMsg)
end
scriptran()
for i,v in ipairs(outputlines) do
print(i,v)
end