Should i split modulescript into multiple modulescripts?

I have a ModuleScript that contains over 1000 lines of code. Different scripts that require this modulescript only need some (like 40%) of the information. The modulescript contains info about materials, some functions and crafting recipes for those materials.
This is an example of my modulescript structure:

local debris = game:GetService("Debris")
local ItemService = {}

ItemService.looseTable = {
	["Sand"] = {
		["Cost"] = 12,
		["Tool"] = "Shovel",
		["MaterialType"] = "Sand",
		["PartProperties"] = {Material = Enum.Material.Sand,BrickColor = BrickColor.new("Brick yellow")},
		["Durability"] = 10,
	},
	["Gravel"] = {
		["Cost"] = 14,
		["Tool"] = "Shovel",
		["SolidItem"] = "Cobblestone",
		["MaterialType"] = "Gravel",
		["PartProperties"] = {Material = Enum.Material.Pebble,BrickColor = BrickColor.new("Medium stone grey"),MaterialVariant = "Gravel"},
		["Durability"] = 12,
		["SolidSize"] = 0.6
	},
}

ItemService.liquidTable = {
	["Molten Iron"] = {
		["Cost"] = 50,
		["Temperature"] = 1538,
		["Solid"] = "Iron",
		["MaterialType"] = "Metal",
		["PartProperties"] = {Material = Enum.Material.Neon,Transparency = 0.2,Color = Color3.fromRGB(255, 140, 0),CustomPhysicalProperties = PhysicalProperties.new(7.85,0.25,1,0.4,1)},
		["SolidSize"] = 1,
	},
	["Molten Stone"] = {
		["Cost"] = 10,
		["Temperature"] = 1200,
		["Solid"] = "Stone",
		["MaterialType"] = "Stone",
		["PartProperties"] = {Material = Enum.Material.Neon,Transparency = 0.2,Color = Color3.fromRGB(255, 183, 0),CustomPhysicalProperties = PhysicalProperties.new(2.7,0.2,1,0.4,1)},
		["SolidSize"] = 1,
	},
	["Water"] = {
		["Cost"] = 0.1,
		["Temperature"] = 0,
		["Solid"] = "Ice",
		["GasTemperature"] = 100,
		["MaterialType"] = "Water",
		["PartProperties"] = {Material = Enum.Material.Foil,Transparency = 0.4,Color = Color3.fromRGB(152, 194, 219),CustomPhysicalProperties = PhysicalProperties.new(1,0.1,1,0.4,1)},
		["SolidSize"] = 1.1,
		["GasSize"] = 3,
		["GasMaterial"] = "Steam",
	}
}

ItemService.toolStatsTable = {
	["Iron"] = {
		["ToolTier"] = 3,
		["Damage"] = 5,
		["Durability"] = 500,
		["HandleModifier"] = 0.004,
		["SpeedModifier"] = 1.2
	},
	["Oak"] = {
		["ToolTier"] = 1,
		["Damage"] = 1,
		["Durability"] = 10,
		["HandleModifier"] = 2,
		["SpeedModifier"] = 0.8
	},
	["Cobblestone"] = {
		["ToolTier"] = 2,
		["Damage"] = 2.5,
		["Durability"] = 100,
		["HandleModifier"] = 0.01,
		["SpeedModifier"] = 0.9
	},
}

ItemService.ItemTable = {
	["Cobblestone"] = {
		["Cost"] = 20,
		["Tier"] = 1,
		["Tool"] = "Pickaxe",
		["CrushItem"] = "Gravel",
		["MaterialType"] = "Stone",
		["PartProperties"] = {Material = Enum.Material.Cobblestone,BrickColor = BrickColor.new("Medium stone grey")}, -- ["Transparency"] = 0.6
		["Durability"] = 20,
		["CrushSize"] = 1.4
	},
	["Glass"] = {
		["Cost"] = 24,
		["Tier"] = 1,
		["Tool"] = "Pickaxe",
		["MaterialType"] = "Glass",
		["PartProperties"] = {Material = Enum.Material.Glass,BrickColor = BrickColor.new("Fog"),Transparency = 0.6,Reflectance = 0.4,},
		["Durability"] = 8,
	},
}

function ItemService:calculateDrop(object)
	-- ~40 lines of code here
end

function ItemService:applyMaterial(part,material,falsetodisableinside,tabletype)
	-- ~15 lines of code here
end

function ItemService:chopPart(object,axis,offset,choppart,plr)
	-- ~170 lines of code here
end

local treeTable = {
	["Oak Tree"] = {
		["Material"] = "Oak",
		["TrunkSize"] = {1.6,2.2,6,12},
		["MaxBranches"] = {2,3},
		["LeavesColor"] = {82, 91, 51, 123, 197, 111},
		["LeavesProperties"] = {Material = Enum.Material.LeafyGrass,MaterialVariant = "LeavesTexture"}
	},
	["Birch Tree"] = {
		["Material"] = "Birch",
		["TrunkSize"] = {1.4,1.8,8,22},
		["MaxBranches"] = {2,3},
		["LeavesColor"] = {100, 120, 90, 123, 197, 111},
		["LeavesProperties"] = {Material = Enum.Material.LeafyGrass,MaterialVariant = "LeavesTexture"}
	},
}

function createInside(treematerial,treepart,usecframe)
	-- 20 lines of code here
end

function createTreeWeld(trunk,root,onTop,rotation)
	-- 10 lines of code here
end

function ItemService:createTree(origincframe,treename)
	-- 100 lines of code here
end

return ItemService

While there is no issues (atleast for now), i am afraid that when i add more recipes, materials and functions in the modulescript it may cause a little lag to all the scripts that may require it.

So should i split this modulescript into material info modulescript, recipes modulescript and functions modulescript?

I tried searching for the answer but i couldn’t find one.

Yeah, split it into functions, materials and recipes. You probably already know that module scripts can require each other

Putting like 99% of your code into 1 script is a bad idea

2 Likes

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