I am rewriting my datastores, as previously, I would get each individual key with it’s data. Now, I am using :Set() on player leave to set the player data like so:
Set
local localPlrStats = plrStats:FindFirstChild(player.Name)
local dataToUpdate = {}
for x, y in pairs(localPlrStats:GetChildren()) do
if #y:GetChildren() > 0 then
for i, v in ipairs(y:GetChildren()) do
table.insert(dataToUpdate, {[v.Name] = v.Value})
end
elseif #y:GetChildren() == 0 then
table.insert(dataToUpdate, {[y.Name] = y.Value})
end
end
DS2("Beta_Key", player):Set(dataToUpdate)
end)
Load/Copy Values into Folder
playerKeys[plr.Name] = keyToGet
print(keyToGet)
for int1, value in ipairs(keyToGet) do
for int2, value2 in ipairs(plrValueObjects) do
if value[value2.Name] then
print("ITEM EXISTS FOR THAT KEY!")
value2.Value = value[value2.Name]
end
end
end
This replicates over my values and their values from a folder in serverstorage to the datastore dictionary holder. When printed, it looks like this:
https://gyazo.com/7514c8706d0691fb8d96c85a08cbd478
However, on player load and after using :Get(), I cannot get the correct values without knowing the index of the dictionary item, which is difficult for loading leaderstats based on value.
Any help?