Using a single ModuleScript with multiple lines versus using multiple ModuleScripts (100++ script) to handle all the item data in the game. Which approach provides the best performance for the game?
Example:
Single ModuleScripts
Multiple ModuleScripts
(edit)
i use Loader for Multiple ModuleScripts to load all module (item data, etc.) into Loader and require Loader to get data, is it good?
This will depend on how many classes you need in your game. It all depends on the size of the module, but I can tell you that for organization, several modules are better.
You don’t need to be that minimalist, Roblox is increasingly giving away processing power to developers. Why make your life harder while they try to improve?
module scripts are just tables that contain functions/variables/other things
in luau tables and functions are passed by reference unlike other datatypes
example
--tables
local tbl = {}
tbl.Cash = 500
local function subtractCashFromTable(t)
-- t is a link to the actual table and not a copy of it, so changes done to t will apply to tbl
t.Cash -= 100
end
print(tbl.Cash) -- 500
subtractCashFromTable(tbl)
print(tbl.Cash) -- 400
-- numbers
local cash = 500
local function subtractCash(c)
-- c is a copy of the actual number and not a link to it, so changes done to c willnot apply to cash
c -= 100
end
print(cash) -- 500
subtractCash(500)
print(cash) -- 500
which means that the performance difference is small because all they do is return a link to a table for other scripts to use
that is also why when changing a value of module script in a script the value will be changed for any other script that used that module, they are all sharing the same table