Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

how do u save/load instances?

Asked by 8 years ago

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)
0
You can't save Instances because they're not automatically serialized. You might want to make your own serialization. User#6546 35 — 8y
0
ok thx tailsninja99 25 — 8y

1 answer

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
8 years ago

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.

Ad

Answer this question