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

Why is this line erroring?

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I have a line in my code that is supposed to save a table that is erroring. The error is, "Cannot store Array in Datastore" Here is my script,

game.Players.PlayerAdded:connect(function(plyr)
    while true do
        wait(60)
        local build=script.Parent

        local pur=build.purchased
        local DataStore = game:GetService("DataStoreService")
        local PlayerData = DataStore:GetDataStore("PlayerData")
        local PlayerD
        local pnumb=#pur:GetChildren()
        local purs=pur:GetChildren()
        local cframes={}
        local number=0
        for i=1, pnumb do
            number=number+1
            local item=purs[number]
            local cframe=item.PrimaryPart.CFrame
            table.insert(cframes,number,cframe)
            print(item.Name)
            print(cframes[number])
        end
        PlayerData:SetAsync(("OBJECTS".. plyr.UserId),purs)
    end
end)

I have no idea why this is erroring as i thought that tables could be saved with datastore. An explanation could be good.

0
ds:SetAsync(key, {v3.x, v3.y, v3.z}) User#9949 0 — 8y

1 answer

Log in to vote
2
Answered by 8 years ago

You can't store Instances in DataStores. In fact, you can't store any userdata or functions of any description, because they can't be serialized properly (And Roblox hasn't added support for serialization of their own userdata). Part of the reason they can't be serialized properly is likely to be the dependency on JSON format, which has no way of practically distinguishing a serialized userdata from a remarkably similar object.

What you'll have to do instead is serialize every member of purs into its fundamental components/properties, and then instantiate them again when they're loaded using the serialized data as a template.

Ad

Answer this question