I'm currently working on an rpg game and i have everything else besides the automatic saving system done. if anyone could tell me whats wrong with this script i would be really grateful.
datastore = game:GetService('DataStoreService'):GetDataStore('Items')
game.Players.PlayerAdded:connect(function(player)
itemsList = {game.ReplicatedFirst.Potato, game.ReplicatedFirst.Gun, game.ReplicatedFirst.Junk}
key = 'player-'..player.userId
savedValues = datastore:GetAsync(key)
if savedValues then
for i, v in pairs(savedValues) do
for a, b in pairs(itemsList) do
if v == b then
item == v:Clone()
item.Parent = player.Backpack
end
end
end
else
datastore:SetAsync(key, {})
end
game.Players.PlayerRemoving:connect(function(player)
datastore:SetAsync(key, savedValues) --I'm not sure this part will work but eh.
end)
end)

2 comments
You can't save Instances because they're not automatically serialized. You might want to make your own serialization.
ok thx