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)
You can't save Instances inside of datastore.
What I reccomend you to do is save a string of the name that the instance has, and make a script that converts those strings into instances, pre-created somewhere.