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

Does a ModuleScript know from where it's been require()d?

And yes sorry it's me the annoying noob.

If not how can you tell the ModuleScript where it's been require()d from?

I cant say

local model = script.Parent

Since I use the require(assetId) method

Update, this is what I have tried

print("Initiating")

local env=getfenv(2).script.Parent
print(env)

Errors Below this line

Initiating 16:51:32.074 - Workspace.Part.SurfaceGui.Updates.MainModule:10: bad argument #1 to 'getfenv' (invalid level) 16:51:32.075 - Script 'Workspace.Part.SurfaceGui.Start.MainModule', Line 10 16:51:32.076 - Stack End 16:51:32.077 - Requested module experienced an error while loading 16:51:32.078 - Script 'Workspace.Part.SurfaceGui.Start.Script', Line 1 16:51:32.079 - Stack End

8 comments

0

You can try passing the script to the module as a variable.

0

I've seen EISS having this feature. I'm not trying to make any form of admin script if you wonder.

0

My suggestion has nothing to do with admin scripts.

0

Yeah im not trying to make one, well thanks for the tip ill try it.

0

Ok it doesn't really work since I will use that ModuleScript at multiple locations.... And therefore I want the correct settings to be loaded. Any other ideas? Meanwhile im waiting for answers(not like panicing take your time) ill try to see how eiss does it.

0

Actually nvm it will work, ill just have one settings script.

0

Holy inactivity, Batman. Use it in a function, not in the module body.

0

I know, how to use it require(assetId)(script.Parent.Settings)

1 answer

It doesn't!
Woo, celebrate!

What you'll find is that normally there's a loader function. Ever had to call it after you require it? That's your loader function. It can use the parent function environment (getfenv(2)) to try and work out where it's being used from.

3 comments

0

Eh sorry, im new to ModuleScripts, I guess this isn't for me...

0

Everyone needs to learn somehow. The deal is that ModuleScripts simply would have no point in knowing where they are initialized from.

0

getfenv(2) seems to don't work, look at my edit above, sorry for inactivity, I have my main connected now because... I thought if I didn't use my Main for ScriptingHelpers I'd get my OBC Theme back, looks like they removed that.

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