Trying to understand ModuleScript access

Hello everyone,

In trying my best to practice the DRY principles, I decided to explore module scripts. I found this wiki on how to create module scripts and call them from other scripts. However, when I tried to replicate what the wiki showed, my code did not work.

I place my ModuleScript in ServerStorage as instructed, but then when I tried to call it using:

local fanFunctions = require(ServerStorage.ModuleScript)

I got an error that ServerStorage doesn’t exist. Once I changed it to the below it worked…

local fanFunctions = require(game.ServerStorage.ModuleScript)

Is there any reason that the wiki wrote it that way, or am I missing something fundamental about scope in this type of solution?

1 Like

ServerStorage is just an example as to where the Module Script would be

If you define it like in your first example, it would be referenced as an “unknown global variable” since there’s nothing defined inside there that’s named “ServerStorage”

But game.ServerStorage would be considered a Service & valid to the script to detect

If you wanted to reference the ModuleScript like that, you could just create a variable to get the ServerStorage:

local ServerStorage = game:GetService("ServerStorage")
local fanFunctions = require(ServerStorage.ModuleScript)

Edit: I need to stop skimming posts
You tried to access ServerStorage from the client (localscript). The client doesnt get any of the server containers. ReplicatedStorage is where you put things you want the client to have access to.

Thanks! That makes total sense.

All good, I do the same thing in other forums lol… I do understand that piece. These particular functions are called in a server side script.