How to sort your scripts?

Hello developers!

I was looking at Roblox Documentation and I found this.
image

I saw on videos where they was using a lot of Module Scripts but they was using few Local Scripts and few Server Scripts.
And my question is: Which way is better and why

Way 1 (Without Modules)

Using only 1 Local Script or Server Script like this:

Server Script:

--[[ex. Equip shoes Function]]--
local function FunctionName()
end

--[[ex. Training Function]]--
local function FunctionName()
end

--[[ex. Remotes Functions]]--
local function FunctionName()
end

and more functions in 1 Server Script or Local Script

Way 2 (With Modules)

Using only 1 Local Script or Server Script like this:

Module Script (ex. UIModule)

local UIModule

-- do stuff in Module
ex.
function UIModule.OnHover()
end

function UIModule.LoadingAnim()
end

return UIModule

Module 2:

local MainModule

-- do stuff in Module
ex.
function MainModule.EquipShoes()
end

function MainModule.Train()
end

return MainModule

Local Script:

local UIModule = require(path to module)

UIModule.OnHover()
UIModule.LoadingAnim()

Server Script:

local MainModule = require(path to module)

MainModule.EquipShoes()

MainModule.Train()

and more functions in module script which can be used in 1 Local Script and 1 Server Script

I would use modules as they are seriously really helpful for scripting, and are more readable. It’s also a great way to learn OOP and I believe it’s very needed for clean code.

1 Like

In my opinion,
It is better and more “satisfying” to use organized modules with 1 main script/local script.

Depending on your game/project tho.

I heavily agree with @Valkyrop. it is better and organized if you used module scripts with 1 main and local script.

Module scripts allow you to use them in multiple scripts,
They can be used both on the client and server side and you should only use them if you need to take data from somewhere but you can still use them if you find it more organizing…

It’s heavily depends on what the circumstances are. If you have a script that’s does something multiple times all the time then you should use a module as it’s something that you repeat on command but if your doing general stuff then you should use normal script, as it won’t make a difference, also one key difference is that when using module they should be in replicated storage witch can be accessed by the client meaning it can be stollen using saveinstance() function on exploits essentially giving exploiters your source code, so keep that in mind. For example I use SSA for a lighting system I made, and I use 1 script as the Handler that controls the function calling and then 1 effect module that stores all the effects. But let’s say I have a shop gui in a simulator game, then a module for the ui is essentially pointless as it helps in no way and does not really need to be used, hence you would usually just use normal local and server scripts.