How to know the source script that called a function inside ModuleScript?

I have a function inside a ModuleScript that is used by both LocalScript and a Server script.
How to know the source script that called this function inside ModuleScript?

function Module.MyFunction()
    -- who called me? 
end
1 Like

You could pass the script object as a parameter for the function.

Module.MyFunction(script)
1 Like

I believe this could help you: How do you check if a module script has been required or if its functions have been called without directly checking in each function?

1 Like

Apparently there is no environment variable that tells which source script called a function.
In this way, this would be the most accurate solution.
But this requires changing the script’s source code.

Although this solution doesn’t identify exactly which script called the function (since I can have multiple LocalScript and multiple Server script), in my case this is the best solution since I won’t need to use additional parameters as suggested by @Downrest.

Thanks.