I’d normally do pretty much OOP to set that up
there’d be a table that stores “items” and each item would have a different class like M4A1 or something more generic like Gun
each class would have a hardcoded schema/fileset to search for, so you’d specifically check for Magazine and store the value of the magazine inside the object
but if you want an unstructured setup similar to yours that converts the instances to a table, I’d have something like this
inventory = {}
storeItem(item)
itemData = {}
addField(item, itemData)
table.insert(inventory, itemData) -- using table.insert in case you have similar items like 2 M4A1s
addField(child, parent)
fieldData = { child.Value, {} } --[1] is the value assuming it's scalar like "M4A1" or 30; and [2] is for any nested fields like isArmorPiercing
parent[child.Name] = fieldData --the index in parent is the fieldname, like "name" or "color" or "isArmorPiercing"
for each child in child
addField(child, fieldData)
-- example usage
storeItem(game.ServerStorage["On Sling"].M4A1)
and then I’d also store the instances a bit cleaner like
Assault Rifle - a StringValue representing an assault rifle - name=Assault Rifle, value=M4A1
Extra - a CFrameValue representing where gun attachments are attached - value=some object CFrame
Grip - a CFrameValue representing where users' hands attach to - value=some object CFrame
Magazine - an IntValue representing how much ammo is left - value=the ammo left
Bullet Type - anything because this is an array and it isnt a scalar value - value=anything
Armor Piercing - a BoolValue representing if the bullets are armor piercing - value=boolean
Drop Rate - a NumberValue representing maybe the number of studs a bullet drops by per second of airtime - value=some number like 1
this would result in a table like
inventory = {
[1] = {
["Assault Rifle"] = {
"M4A1",
{
Extra = { CFrame.new(...), {} },
Grip = { CFrame.new(...), {} },
Magazine = {
30,
{
["Bullet Type"] = {
null,
{
["Armor Piercing"] = { true, {} },
["Drop Rate"] = { 1, {} }
}
}
}
}
}
}
}
}
you could add a bit more to remove the redundant data and turn {1, {}}
to just 1 also
Also note that I prefer doing it with OOP because you’d have less redundancy from not needing to store Grip, Extra, Armor Piercing, Drop Rate for each M4A1. That data that’s shared between each is stored separately only once
I would also strictly use in-code inventory systems and not use Value instances like StringValue and IntValue at all by just storing the table and working directly with it