For some reason getfenv() isn’t returning local variables, only global variables. The problem is that my “global variables” are declared locally if that makes sense
local CoolFolder = workspace
local environment = getfenv();
for i,v in pairs(environment) do
print(i, v);
end
Is there a workaround for this or do I have to declare my variables globally?
getfenv returns the environment of the provided function (or stack level). An environment is a Lua table of global variables, with the keys being their names and the values being their values. Local variables are stored in a stack, which allows for faster retrieval.
We would be able to access local variables and external local variables with debug.getlocal and debug.getupvalue, but Roblox removed these functions. There is no way to programmatically get local variables. May I ask why you need to do this?
I have a few “container” objects and by that I mean a lot so I was thinking of making a :GetContainer function which takes the variable name as a parameter and then returns the variable