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

Why is this printing things?

setfenv(function()end,setmetatable({},{__index=print}))()

This should not print anything, but the output says

table: 1CF65F98 script

table: 1CF65F98 script

similarly, this should error "lag" but something mysterious causes otherwise

local c,tick,error=tick(),tick,error
setfenv(1,setmetatable({},{
	__index=function(t,k)
		--print(t,k)
		return rawget(t,k)
	end})
);
(function(f)
	return f(f)
end)(function(f)
	if tick()-c>1 then
		error("lag")
	end 
	return f(f)
end)

This only happens in Roblox. What is going on?

2 comments

0

Lol you are soo advanced in scripting, I feel like no one would know how to help you :P

0

This is easy to understand.

1 answer

This happened to me a couple of months ago, I'm not entirely sure why it's exactly happening but here were my conclusions:

local print = print

local function func()
	print("Blah")
	print("kah")
	local y = 3
end

setfenv(func, setmetatable({ script = 123 }, {
	__index = function(self, key)
		-- getfenv(0) == getfenv(1) == getfenv(3)
		-- getfenv(2) == getfenv(func)
		print("Current env", getfenv(1), rawget(getfenv(1), "script"))
		print("Caller env", getfenv(2), rawget(getfenv(2), "script"))
		print("Caller of Caller env", getfenv(3), rawget(getfenv(3), "script"))
	end
}))

print("func Function Environment", getfenv(func))
print("Global Environment", getfenv(0))
print("Enclosing Function Environment", getfenv(1)) -- should be the global environment

func()

It seems like every time I do something in func, __index is invoked. It leads me to believe it might be the script debugger or something but I have no idea. Although I believe this only happens in studio as well, don't remember. If it's not the debugger then I have no idea what it is but they definitely tampered with Lua as it's invoked even when I define a local variable.

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