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

Using _G Functions help?

So i've made a global function,So i want this function to basically print out the name of the script that ran it. Such as,If the script "LolHax" accessed the function,The function would print out the script that used it (In this case LolHax),And not print out the name of the script its located in.

Help much appriciated.

1 answer

✓ Accepted answer

Say you have a script named a:

_G.var=function()
	print(script.Name)
end
_G.var()

and a script named b:

wait()
_G.var()

This will print "a" twice. If you want to get the script that the function is called from, you need to access its function environment, so a becomes

_G.var=function()
	print(getfenv(0)["script"].Name)
end
_G.var()

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