#Goal:# My Current goal it to save an inventory. The inventory is those that contain an ImageLabel with an image and a Text label to display the quantity of that item.
#Problem:#
My problem is that currently when I save things such as "money" I use Instance.new() to hold the value and save/load from that. But say I wanted to make a system where it has a quantity of an item? I don't want to create more Instance.new() and based on how many different items there are there will be a lot of IntValues in a folder. So I want to learn a different way of doing this.
#Script (This is a section):# This is a ServerScript in ServerScriptService
game.Players.PlayerAdded:Connect(function(plr)
local Stats = Instance.new('Folder')
Stats.Name = 'Stats'
Stats.Parent = Player
local ExampleStat = Instance.new('IntValue')
ExampleStat.Name = 'ExampleStat'
ExampleStat.Value = 0
ExampleStat.Parent = Stats
end)
local function Print(message) -- Ignore my for fun stuff
if PRINT_OUTPUT then print(message) end
end
local function SaveData(player)
if player.UserId < 0 then return end
player:WaitForChild("Stats")
wait()
local Stats = {}
for i, stat in pairs(player.Stats:GetChildren()) do
table.insert(Stats, {stat.Name, stat.Value})
end
leaderboardData:SetAsync(player.UserId, Stats)
Print('Printing Report From: '..script.Name)
Print('Report: '..player.Name.." ["..player.UserId.."]".."'s data was Saved!")
end
local function LoadData(player)
if player.UserId < 0 then return end
wait()
player:WaitForChild("Stats")
wait()
local leaderboardStats = leaderboardData:GetAsync(player.UserId)
print(leaderboardStats)
for i, stat in pairs(leaderboardStats) do
local currentStat = player.Stats:FindFirstChild(stat[1])
if not currentStat then return end
currentStat.Value = stat[2]
end
Print('Printing Report From: '..script.Name)
Print('Report: '..player.Name.." ["..player.UserId.."]".."'s data was Loaded!")
end
players.PlayerAdded:Connect(LoadData)
players.PlayerRemoving:Connect(SaveData)
if SAFE_SAVE then
game.OnClose = function()
for i, player in pairs(players:GetChildren()) do
SaveData(player)
end
wait(1)
end
end
while AUTO_SAVE do
wait(TIME_BETWEEN_SAVES)
for i, player in pairs(players:GetChildren()) do
SaveData(player)
end
end
Chances are I will have to deal with tables. Basically, I don't want to Instance.new() spam. Or else If a game had 50 items I would need 50 IntValues. and 50 Instance.new()'s
So how could I do this? Can someone please provide a template or an example? Thank you for reading and I appreciate any helpful feedback.

6 comments
Save the .Value of the object to a DataStore ... Please ask specific questions.
How do you save that?
Is the name of "NPCItems" that you have to find the value of constant? Or does it change?
IT Changes
I believe that you can't really make an changes to it, coming from someone who is intermediate at scripting. Someone else might say that it could be improved, but it seems fine to me.
I see