New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote

Why is this line erroring?

Asked by 3 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,

    while true do
        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
            local item=purs[number]
            local cframe=item.PrimaryPart.CFrame
        PlayerData:SetAsync(("OBJECTS".. plyr.UserId),purs)

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

ds:SetAsync(key, {v3.x, v3.y, v3.z}) Turtletowerz 1078 — 3y

1 answer

Log in to vote
Answered by
eLunate 5075 Trusted Moderation Voter Community Moderator
3 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.


Answer this question