You can do this with getfenv()
getfenv returns the environment of a given function or script. It returns a table for all declared function in the script so far.
local a = 'thing'
b = 'another thing'
local env = getfenv()
print(env) -- {['b'] = 'another thing'}
print(env['a']) -- 'thing
print(env['print']) -- function 0xblahblah
the reason why a or print doesn’t appear in the actual table is because it doesn’t store builtins or local variables in this table so unfortunately you can’t loop through all the variables in a script. However when indexed it returns the value of the variable through metatables which is why env[‘a’] returns something even though there is nothing in the table.
You can read more here and I only understand about 90% of what getfenv does cause it has a parameter. But if you wanna get the builtin functions then its useful cause almost all env’s (unless manipulated return the same builtin functions.
I think he meant he doesn’t wanna use loadstring in general