Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how do u save/load instances?

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

0

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

0

ok thx

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.