So I have bool values in a folder but depending on the player there are different amounts of boolvalues so I need to saving all using a table. I am not quiet sure how to do so.
local datastore = game:GetService("DataStoreService"):GetDataStore("Cards")
game.Players.PlayerRemoving:connect(function(player)
player:WaitForDataReady() -- make sure we aren't looking for leaderstats before they are created
wait(2) -- just in case
local stats = player:FindFirstChild("Cards"):GetChildren()
for i = 1, #stats do -- creates a loop for all the stats
print(stats[i].Name)
datastore:SetAsync(stats[i].Name, stats[i].Value)
end
end)
-- Loading dem stats
game.Players.PlayerAdded:connect(function(newplayer)
newplayer:WaitForDataReady() -- make sure we aren't looking for leaderstats before they are created
wait(2) -- just in case
local stats2 = newplayer:FindFirstChild("Cards"):GetChildren()
for i = 1, #stats2 do
stats2[i].Value = datastore:GetAsync(stats2[i].Name)
end
end)

1 comment
You don't need WaitForDataReady.