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,
game.ServerScriptService:WaitForChild("MainProperties")
local mainproperties = require(game.ServerScriptService.MainProperties)
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.
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.
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)
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.