Module Script Issue

Recently, I discovered the glory of module scripts. I decided to use a module script for the main properties in my UI since the properties are pretty clouded and it would make it way easier to make.

However, when I try requiring the module script from a local script (not sure if you can’t require them from a local script), it seems to not pick it up. Does anyone know why this isn’t working?

If local scripts can’t require module scripts, is there any other way they could? I heard that using “init” can solve this issue, however, I am not quite sure how to use it.

Here is my code,

local mainproperties = require(game.ServerScriptService.MainProperties)
1 Like

A local script does not have access to the server. It can require client sided modules though. Also, put this in scripting support. (EDIT: It appears you have now nvm)


You’re trying to require a ModuleScript that’s in a server-only container on the client. Move MainProperties to ReplicatedStorage or somewhere else that clients can see to fix it.


He is trying to require a module script in ServerScriptService from a local script, which is impossible.

Doesn’t seem to work, either.
I’ll try doing something else.

Are you returning anything as well? A module needs to return something.


local mainproperties = {}

-- services

mainproperties.httpservice = game:GetService("HttpService")
mainproperties.serverscriptservice = game:GetService("ServerScriptService")
mainproperties.replicatedservice = game:GetService("ReplicatedStorage")
mainproperties.teleportservice = game:GetService("TeleportService")
mainproperties.startergui = game:GetService("StarterGui")

-- demo ui properties

mainproperties.loadingui = mainproperties.startergui.LoadingUI

return mainproperties

Yes, but I did not notice that before, but still, you CAN run ModuleScripts from LocalScripts. If it’s available, of course.

And I tried to run it from replicatedstorage, too.

Yes, you can. I was just saying he has to put it somewhere where the client can access it as well.

So it does return something. Have you moved it from ServerScriptService to somewhere like ReplicatedStorage, a place that any client can access?

EDIT: Also I just noticed you are trying to make variables from the starter gui. Instead, just make a local script inside of the gui. Then have a module script inside of it and have the variables be the script parent instead. You can not use the screen gui since it is copied to the player gui instead.

1 Like

Yes, I have. I tried moving it to replicatedstorage and I get a red underline on the require line.

local mainproperties = require(game.ReplicatedStorage.MainProperties)

Read my new EDIT in the post above ^^^^

The WaitForChild not having a variable assigned to the returned value has nothing to do with the red underline, and there’s nothing wrong with using it like that as long as you’re not throwing away what WaitForChild returns unnecessarily. (aka waiting for a instance and then setting a variable to it instead of setting the variable to what WaitForChild returned)
(by the way, if you have the module in ReplicatedStorage you don’t need to WaitForChild for it)

Yup, that seemed to work.

For further explaination, you meant that the module script can’t access startergui from another service? If I wanted to have startergui properties and other properties, how would I do that?

I mean you have to use the gui inside of the player gui. A simple way of doing this is simply having the local script/module inside of the gui you want. Then instead of getting the gui from screenGui, simply use script.Parent or whatever your hierarchy is.

1 Like

Ah, I see. Makes more sense now.


No problem, good luck! :slight_smile: