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

Cannot store Instance in DataStore?

Asked by 5 years ago
Edited 5 years ago

I am trying to save objects the player has built but I get the error in the title

script in ServerScriptService:

local Data = game:GetService('DataStoreService'):GetDataStore('Data0')
local prefix = 'user_'
game.Players.PlayerAdded:Connect(function(plr)
    -- Define variables
    local uniquekey = 'id-'..plr.UserId
    local Storage = Instance.new("Folder")
    Storage.Parent = plr
    Storage.Name = "Storage"
    local Objects = Storage:GetChildren()
    print("Loading boat...")
    local function Load()
    local plrData = Data:GetAsync(prefix  .. tostring(plr.UserId))
    if plrData then
        Storage:GetChildren(Objects)
        Data:SetAsync(uniquekey, Storage)
        print("Loaded :D")
     else
       print("Data wasn't loaded.")
       Data:SetAsync(prefix  .. tostring(plr.UserId), {
        print("Trying again."),
        Storage:GetChildren(Objects),
        Data:SetAsync(uniquekey, Storage),
        print("Loaded")
        })
    end
    end
Load()
end)
game.Players.PlayerRemoving:Connect(function(plr)
    print("Saving data for",plr.Name)
    Data:GetAsync(prefix .. tostring(plr.UserId))   
end)

The problem is at line 22.

0
you can't store instances in datastores (parts, folders, guis etc.) but you can store information about them inside of tables/dictionaries radusavin366 617 — 5y
0
Then how would I store the objects? Do I make it a child of leaderstats? mixgingengerina10 223 — 5y
0
if the objects are values just store the values inside a table, then SetAsync(uniquekey, *tablename*) radusavin366 617 — 5y
0
Can you give me an example? am really confused mixgingengerina10 223 — 5y
View all comments (7 more)
0
if not just store information about them (position, rotation, size if theyre a part for example) inside the table with their own key radusavin366 617 — 5y
0
you can look around this tutorial for examples: https://www.robloxdev.com/articles/In-Game-Currency-with-Roblox radusavin366 617 — 5y
0
They're objects not values... mixgingengerina10 223 — 5y
0
You can't store objects (instances) in DataStores. Only string and numbers hellmatic 1523 — 5y
0
you don't even save the data when they leave lol green271 635 — 5y
0
Ik, I tried this:local Objects = {} local get = plr.leaderstats.Storage:GetChildren() local uniquekey = 'id-'..plr.UserId print("Saving data for",plr.Name) for i, v in pairs(get) do table.insert(uniquekey, v.Name) Data:GetAsync(uniquekey, Objects) print("Saved") end, but I get this error:bad argument #1 to 'insert' (table expected, got string) mixgingengerina10 223 — 5y
0
Because uniquekey is not a table.! User#19524 175 — 5y

Answer this question