I know there was already a question somewhat like this, but I didn't fully understand the answer. The error that I get from this script is that you can't store an array in datastore. So how would I store a table of the player's backpack in a datastore?
local DSS = game:GetService("DataStoreService")
local datastore = DSS:GetDataStore("GeneralSaveData", "Players")
function generateDataKey(player)
local ret = "uid_" .. player.userId
return ret
end
function generateDataTable(player)
local dataTable = {}
for _, tool in ipairs(player.Backpack:GetChildren()) do
table.insert(dataTable, tool.Name)
end
return dataTable
end
function saveDataForPlayer(player)
local key = generateDataKey(player)
local data = generateDataTable(player)
datastore:SetAsync(key, data)
end
function inputDataToPlayer(player, data)
if data then
for _,T in pairs(data) do
local wep = game.ServerStorage.Weapons:FindFirstChild(T)
if wep then
wep:Clone().Parent = player.StarterGear
wep:Clone().Parent = player.Backpack
end
end
end
end
function loadDataForPlayer(player)
local key = generateDataKey(player)
local data = datastore:GetAsync(key)
inputDataToPlayer(player, data)
end
game.Players.PlayerAdded:Connect(function(player)
loadDataForPlayer(player)
end)
game.Players.PlayerRemoving:Connect(saveDataForPlayer)
There's probably other errors in the code that I didn't notice, so if you see any feel free to correct them.

1 comment
Store the name of the object; you cannot save instances to datastores