I’m trying to save all the children of a folder using data store. basically, this folder will be in the player. In it will be all boats they have unlocked. How would I save all children of this folder to data store
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = player
leaderstats.Name = "leaderstats"
local Boats = Instance.new("Folder")
v.Name = "Boats"
v.Parent = player
local Equipped = Instance.new("StringValue")
a.Name = "Equipped"
a.Parent = player
local Loot = Instance.new("Folder")
b.Name = "Loot"
b.Parent = player
local data1
local data2
local data3
local success, errormessage = pcall(function()
data1 = myDataStore:GetAsync(player.UserId.."-boats")
data2 = myDataStore:GetAsync(player.UserId.."-equipped")
data3 = myDataStore:GetAsync(player.UserId.."-loot")
end)
if success then
v.Value = data1
a.Value = data2
b.Value = data3
print("Successfuly saved data")
else
print("There was an error whilst getting your data")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-boats",player.leaderstats.Boats.Value)
myDataStore:SetAsync(player.UserId.."-equipped",player.leaderstats.Equipped.Value)
myDataStore:SetAsync(player.UserId.."-loot",player.leaderstats.Loot.Value)
end)
if success then
print("Player data successfully saved!")
else
print("There was an error when saving data")
warn(errormessage)
end
end)
end)