How can I get the name of the script which is using a module script?

Eg. if a script called “Foo” is calling a module script function, I want to somehow retrieve “Foo” (or just the “Foo” script instance).

Example:

-- "Bar" module script
local mod = {}

function mod.hello()
  print("Script '" .. (?) .. "' says hello!")
end

return mod

-- "Foo" script
local bar = require(Bar)

bar.hello()

-- Output: Script 'Foo' says hello!

You can use debug.info with the s option.

=debug.info(2, "s") --> "blah.blah.foo.Foo"
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.