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

How do i store objects in a Datastore???

Asked by
NexeusX 137
7 years ago

I know the basics of Datastores but i do not know how to save objects...This script is suppose to make a folder in the player, and if there are any Tools/Bricks/Models/etc...inside of that folder then insert them into a table and save them to the datastore. It does not work though so what i can i do to store and load them?

local DataStore = game:GetService("DataStoreService"):GetDataStore("BackPack")
game.Players.PlayerAdded:connect(function(player)

local Storage = Instance.new("Folder",player)

Storage.Name = "Storage" --Name of folder

local key = "user-" .. player.userId --Key
local storeditems = DataStore:GetAsync(key)

if storeditems then
    storeditems.Parent = Storage
    else
        local items = {} --Items table

        local get = Storage:GetChildren()-- get items
        for i, v in pairs(get) do --save tools
        table.insert(key, v)
        DataStore:SetAsync(key, items)


        end
    end
end)


game.Players.PlayerRemoving:connect(function(player)
    local items = {}
    local key = "user-" .. player.userId

    for i, v in pairs(get) do --Save tools
    table.insert(key, v)

    DataStore:SetAsync(key, items)

    end
end)

1 answer

Log in to vote
1
Answered by 7 years ago

Serialization

You can't store Instances. Roblox doesn't serialize them, because JSON has no support for them, and Roblox doesn't support binary data structures for storage (Truth - Roblox actually doesn't like a lot of binary values).

The solution?
Store the information which describes the Instance. Is it an IntValue? Store the number. Part? Store the information to make it, such as the name of the thing you cloned it from. Weapon? Store the name. Serialization is an important part of storage which was missed out from DataStores for some unknown reason.

0
and how exactly i do this? i want make a script that save the object that is touching a part, and when enter, he will load this object again, how i do this? darkzerobits 92 — 6y
0
and how exactly i do this? i want make a script that save the object that is touching a part, and when enter, he will load this object again, how i do this? darkzerobits 92 — 6y
Ad

Answer this question