Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Cesire 45
8 years ago

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

0
You can try passing the script to the module as a variable. LightningRoMan 100 — 8y
0
I've seen EISS having this feature. I'm not trying to make any form of admin script if you wonder. Cesire 45 — 8y
0
My suggestion has nothing to do with admin scripts. LightningRoMan 100 — 8y
0
Yeah im not trying to make one, well thanks for the tip ill try it. Cesire 45 — 8y
View all comments (4 more)
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. Cesire 45 — 8y
0
Actually nvm it will work, ill just have one settings script. Cesire 45 — 8y
0
Holy inactivity, Batman. Use it in a function, not in the module body. User#6546 35 — 8y
0
I know, how to use it require(assetId)(script.Parent.Settings) Cesire 45 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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.

0
Eh sorry, im new to ModuleScripts, I guess this isn't for me... Cesire 45 — 8y
0
Everyone needs to learn somehow. The deal is that ModuleScripts simply would have no point in knowing where they are initialized from. User#6546 35 — 8y
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. Cesire 45 — 8y
Ad

Answer this question