I have a data store system that saves a players house and the items they have. Problem is, I store all furniture info (item, color, position, etc.) inside a table. If you have 2 Chairs for example, it rewrites the old chairs data, with the other chair, and thus only 1 chair gets saved
local Items = {Exterior = {}, Interior = {}, Landscape = {}, Furniture = {}}
-- Get the furniture
for _, item in pairs(PlayersInterior.Build.Furniture:GetChildren()) do
print('Grabbing furniture')
local PurchaseData = {}
local PrimaryPart = item.PrimaryPart
local Position = PlayersInterior.PrimaryPart.CFrame:inverse() * PrimaryPart.Position
local Direction = PrimaryPart.CFrame.lookVector
PurchaseData.Position = {
Position.X,
Position.Y,
Position.Z,
Direction.X,
Direction.Y,
Direction.Z
}
local Primary = item:FindFirstChild('Primary')
PurchaseData.Primary = Primary.BrickColor.Name
local Secondary = item:FindFirstChild('Secondary')
if Secondary then
PurchaseData.Secondary = Secondary.BrickColor.Name
local Tertiary = item:FindFirstChild('Tertiary')
if Tertiary then
PurchaseData.Tertiary = Tertiary.BrickColor.Name
end
end
print('Adding', item.Name, 'to data')
Items.Furniture[item.Name] = PurchaseData
end
And then with this table, I use a module that converts the table into Values, so I can store it with DataStore2
local NewDataFolder = Converter.Convertr(Items)
NewDataFolder.Name = PlayerData.House.Value
But my main question lies with how to store multiple items with the same name? I know it has something to do with this line
Items.Furniture[item.Name] = PurchaseData
Basically, if there’s a ‘Chair’ already saved, then it gets that Chair, instead of creating a new ‘Chair’ with its own PurchaseData
EDIT It needs to look like this basically
Items.Furniture = {
['Chair'] = {
-- CFrames, Color, etc.
},
['Chair'] = {},
-- CFrames, Color, etc.
},
}
Where as at the moment, it only saves 1.
I tried
Items.Furniture[#Items.Furniture + 1] = PurchaseData
And yes this saves all chairs, but the name of each one is now 1, 2, 3, 4, etc.