To make a long story short, I'm wondering if it's possible to save, specifically, the children of a value (IntValue) in a DataStore. For example, if you have a value called "Money" and it has a child called "Quarter" secondarily added to it, Quarter would become part of the datastore and would save across play sessions. Here is a method I tried to use to do this, although I get an error saying that Arrays can not be saved in datastore.
DS = game:GetService("DataStoreService")
DataStore = DS:GetDataStore("PlayerCurrencies")
local ServerStorage = game:GetService('ServerStorage')
local RS = game:GetService("RunService")
game.Players.PlayerAdded:Connect(function(player)
local Money = Instance.new('IntValue')
Money.Name = 'Money'
Money.Parent = player
local Children = Money:GetChildren()
local Inventory = Instance.new('Folder', player)
Inventory.Name = player.UserId
local data
local success, err = pcall(function()
data = DataStore:GetAsync('playerdata_'..player.UserId)
end)
if success then
print('sucess in set async')
if data then
print('data collected')
Money.Value = data[1]
for i, Child in pairs(Children) do
Child.Parent=Money
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Money = player.Money
local Children = Money:GetChildren()
local ChildTable = {}
for i, Child in pairs(Children) do
table.insert(ChildTable, Child)
end
local data = {Money.Value, ChildTable}
local success, err = pcall(function()
DataStore:SetAsync('playerdata_'..player.UserId, data)
end)
if success then
print('data has saved'..Money.Value..ChildTable)
else
warn(err)
print(Children)
print(ChildTable)
end
end)
game:BindToClose(function()
wait(2)
end)
If this is unfixable, is there any alternate methods I could try to use? Thank you.
