I'm trying to make a script that uses a script that saves the player's inventory if they leave the game. Here's what I have so far:
local ds = game:GetService("DataStoreService"):GetDataStore("tools")
game.Players.PlayerAdded:connect(function(player)
local key = "user_" .. player.userId
ds:UpdateAsync(key, function(old)
old = game.Players.LocalPlayer.Backpack:GetChildren()
if old:IsA("Tool") then
local new = old or nil
local tool = old:Clone()
tool.Parent = game.Players.LocalPlayer.Backpack
return new
end
end)
end)
I copied some of it from the wikia. I think I'm doing it all wrong. Please help!

1 comment
You cannot save instances with datastore you can only save values and tables, those sort of things.