How do most developers organize their scripts?

I want to know how developers organize their scripts, like how often do they use functions, and why do they use them, or how they use modules and stuff. So, I can make my scripts look more nicer and more organized.

1 Like

Usually people (some people) would organize their scripts with --comments, Just to stay organized,
For Example:

----/ Variables / --------

local Players = game.Players
local Money = workspace.Money

----/ Sounds / --------

local Sound = workspace.Audio.Sound

-- and so on..

Many people would also use ModuleScripts for Specific data, and even making Sub Modules for that Module.

Even with certain Connections:

local module = {}

module.OtherModule = require(script.ModuleScript)

module.PlayerJoin = game.Players.PlayerAdded
module.PlayerLeft = game.Players.PlayerRemoving
local mod = require(module)

mod.PlayerJoin:Connect() -- Useless, but Valid
mod.OtherModule -- Access to another Module
3 Likes

How do they use ModuleScripts?

In general things should be grouped by how independent they are. If you have several lines of code that have well defined inputs and outputs/effects, odds are you can make that its own function. If you have several functions that need to be used together, or work on similar data, or serve the same purpose, that in turn can probably go in a module.

2 Likes

Personally I love modules, I use them for creating tables with for example the Stats of the Weapons, Tools, Items stats, everything that could be required for many other scripts.

I used them too to save player’s data as a holder, when player joins, I collect their datastore, and place it on a new entry in a module table, if player buys stuff, sell, gain stats, currency etc, I have that module table to edit everything the player does, and when player leaves I grab that table, and save it into their datastore and flush the table.
Having all that data in a module gives lot of flexibility when many other scripts wants to deal with that data and edit it.

And I use modules to hold important functions that will happen many times in game, like whats gonna happen when player dies, I would have a module function to handle that, and just call it whenever I need it

Interesting, I never thought of it that way, I thought folders with a bunch of values was the best way to hold a player’s stats while there in a game. But no, the module idea was very cool. I will use that idea in future projects.

1 Like

Actually I dont like to have folders and saving values in them, for me using modules tables its way better, faster, and for my head its easier to know exactly where is everything related with players

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.