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.
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()