Would it be better to separate this into two module scripts? One would create a new item and include any additional methods. While the other initializes the module scripts, each containing data for the item, and includes a get method to retrieve the item data.
local Item = {}
Item.__index = Item
local _data = {}
function Item.new(itemData: table)
local self = setmetatable({
Name = itemData.Name,
Icon = itemData.Icon,
SellPrice = itemData.SellPrice,
StackSize = itemData.StackSize,
Quantity = itemData.Quantity,
CanStack = itemData.CanStack,
CanHold = itemData.CanHold
}, Item)
return self
end
local function _Init()
for _, module in script:GetChildren() do
local newModule = require(module)
_data[module.Name] = newModule
end
end
function Item.Get(itemId: string)
return _data[itemId]
end
function Item.IsATool(item: table): boolean
if item.Model == nil then return false end
if item.Model:IsA("Tool") then
return true
end
end
_Init()
return Item