I know that Datastores cant save instances, but they can save their properties.
basically I am trying to get the gears in the players backpack and another folder (their owned gears) saved by getting the names of the gears, and when they rejoin, the script will detect the names in the table and find the gears in serverstorage and clone to respected area (backpack OR owneditems folder)
here is the code to this function
function SaveData(Plr)
local KillsData = Plr.leaderstats.Kills.Value
local BricksData = Plr.leaderstats.Bricks.Value
local OwnedGears = {};
local GearsInBackpack = {}
for i,v in pairs(Plr.OwnedGears:GetChildren()) do
--if v and v.Name then
OwnedGears[v.Name] = v.Name
--end
end
for i,v in pairs(Plr.Backpack:GetChildren()) do
if v.Name ~= "ZZChute" then
GearsInBackpack[v.Name] = v.Name
end
end
for i,v in pairs(OwnedGears) do
print(v) -- It SHOULD print out all names in the folder (sometimes it would print out a fraction of the stuff)
end
for i,v in pairs(GearsInBackpack) do
warn(v) -- It SHOULD print out all names in the backpack except one (sometimes it would print out a fraction of the stuff)
end
local Success, Err = pcall(function() -- I could put this in 1 table but i am too lazy
LeaderboardData:SetAsync(Plr.UserId, BricksData)
LeaderboardData2:SetAsync(Plr.UserId, OwnedGears)
LeaderboardData3:SetAsync(Plr.UserId, GearsInBackpack)
LeaderboardData4:SetAsync(Plr.UserId, KillsData)
end)
if Success then
print("Data has been saved!")
else
print("Data hasn't been saved!")
warn(Err)
end
end
Yeah as HyperD3v said, you must do table.insert. What you’re telling the Datastore is to find v.Name inside that table by doing OwnedGears[v.Name], to insert things inside a Table you must do table.insert and that is the only way. Hopefully this helps you understand a little more about how Table’s work, have a good day
I hope you did the getting data part, I mean if you didn’t do it then it can’t get the data, it saves, but it can’t get the data and also use table.insert(), how HyperD3v said.