Ideas on saving multiple items, with different information

Other ways of saving or efficient way of saving multiple item, with different information such as health, attack, etc. My current idea of saving is using the name of the attribute that I want to save:

data = {
	{
		Item = "...",
		Replica = 0,
		Attack = 1,
		Health = 1
	},
	{
		Item = "...",
		Replica = 1, --If the item already exist; for the gui.
		Attack = 10,
		Health = 10
	},
	{
		Item = "idk",
		Replica = 0,
		Attack = 10,
		Health = 10
	}
}

It depends on where you’re storing this. Is it player data that you store in DataStores, or just configuration information that remains unchanged?

1 Like

you can use attributes on the instance it self

or you can use a module

-- moduleScript

return {
	["ItemName1"] = {
		Attack = 1,
		Health = 2,
	},
	["ItemName2"] = {
		Attack = 6,
		Health = 8,
	},
	["ItemName3"] = {
		Attack = 4,
		Health = 1,
	},
}
-- any other script
local itemData = require(game.ReplicatedStorage.ItemData)
print(itemData[item.Name].Health)
1 Like

It’s a player data, I can’t use the exact name of the item as a key for the table, because the player will have the same item but different stats, some may have more stat attributes(not the value of the attribute) some may have less.

In this case, your format is suitable. You can avoid storing some useless properties for each of your items by defining default values for these properties, that will exist only at runtime and won’t be saved, but this is good enough already.

1 Like