Is this unnecessary?

Heyo I’ve been trying to see how I could use modules more and I realized like what if I put all my commonly used variables in one module instead of having to rewrite them everytime although I’m not sure if that just makes things complicated, but basically instead of having to write this in every script

local RepStorage
local ServerStorage
local Players

I put them in a module

local Module = {}

--| Services
Module.Players = game:GetService("Players")
Module.RepStorage = game:GetService("ReplicatedStorage")
Module.SSS = game:GetService("ServerScriptService")
Module.ServStorage = game:GetService("ServerStorage")
Module.MPS = game:GetService("MarketplaceService")

return Module

So is this a good use for modules? Or should I just rewrite the variables in each script?

Well it’s doable, but how often are you using those services? Are you using them in 5 different scripts? 15, 20? It just depends on how you’re using them.

This is essentially the same as having them as variables in your code.

Instead of referencing “RepStorage”, you’d have to reference moduleName.RepStorage.

If you don’t think this looks nice, you can always table the services, it’s not the neatest when others have to read your code but it’s up to you.

local services = {

   -- Whatever here

If your looking for how you would use modules more, I personally use my modules for storing important functions, say like creating a new button on some UI. Other things would be a “Config” module. This stores all the important stuff (an example would be the distance required for a user input to show a gui).

Yes, you could do this, but it just means your going to have to reference the module in every single piece of code you need it to be in. If someone wants to easily read your code, they need to go into the module to see what services you are using (if you named the variables poorly)

1 Like