How to get the "script" variable from a function?

Ok, I am just gonna go sleep with the thinking of making a Signal API.

How ever, I would like to be able to smartly disconnect functions from scripts that were deleted.

(Even if this ends up not being necessary, it’s still something I wanna learn for other reasons)

Basically I would like to know how to get the script “variable”, from a given function. Let’s say a script gives a function as an argument, I wanna use that to determine what script that was called from, however, I don’t know how to do that.

I think you can do that with getfenv()? I’m not sure. I would like some help from some “professional” scripters out here.

1 Like

If I don’t view what you guys said right away, it’s because I’m going to sleep. (Yes at 5 am yay suffering.)

Oh ok I THINK this works:

Just be a little cautious when you’re using getfenv(). There were some notes about it when Luau was released and so on.

Hm? Ok… I never used getfenv, never was useful until now. What actually are you talking about?

It disables Luau’s optimizations. I remember it being mentioned in a different topic:

1 Like

Hm, I was gonna say it probably doesn’t “disable them” but nvm, It looks like it does.

That’s kind of sad. I think it might not be a problem since I’m only getting the env from the submitted function, and most people use local variables anyway, but stuff like the math, table, string, libraries I guess can cause problems.

I feel like there should be a function to allow getting a script object from a function at this point :crying_cat_face: