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

Cannot store Array in DataStore?

Asked by 6 years ago

I am trying to save a table of values to a datastore but It says its an array even though they are all values.

    local PSavedData = PrimaryDataStore:GetAsync(id)
    if PSavedData then
        PTransparency.Value = PSavedData[1]
        PLocalColor.Value = PSavedData[2]
        PMeshId.Value = PSavedData[3]
        PMeshTextureId.Value = PSavedData[4]
        PPETextureId.Value = PSavedData[5]
        PSpread.Value = PSavedData[6]
        PPELocked.Value = PSavedData[7]
    else
    local PDataForSaving = {
            PTransparency.Value, 
            PLocalColor.Value, 
            PMeshId.Value, 
            PMeshTextureId.Value, 
            PPETextureId.Value, 
            PSpread.Value, 
            PPELocked.Value
        }
    PrimaryDataStore:SetAsync(id, PDataForSaving)
    end
1
Color3 values cannot be saved. You need to save each part of a Color3 separately. hiimgoodpack 2009 — 6y
0
Lol i just thought about that before I refreshed the page ForKaznia 6 — 6y

1 answer

Log in to vote
2
Answered by 6 years ago
Edited 3 years ago

Color3 values cannot be saved via datastore in its original format. In order to get around this problem, we can store each variable of the Color3 value into a table. Once we've done this, we can save this value using JSONEncode that allows us to convert the table into a string in a format where DataStore can save it (JSON: http://wiki.roblox.com/index.php/JSON. Use this as an example.

local NewTable = {PARTNAME.Color.r,PARTNAME.Color.g,PARTNAME.b}
local JSONTable = game:GetService("HttpService"):JSONEncode(NewTable)
PrimaryDataStore:SetAsync(id, JSONTable)
--In order to load the color we saved we can do something like this--
local ColorTable = PrimaryDataStore:GetAsync(id)
local DecodedTable = game:GetService("HttpService"):JSONDecode(Color3Table)
local ColorValue = Color3.new(DecodedTable[1],DecodedTable[2],DecodedTable[3])
0
This is a great way of doing this; great job! lazycoolboy500 597 — 6y
0
THANK YOUUUUUUUUUUUUUUUUUUUUUUUUUUUU!!!!!!!!!!!!!!!!!!!!!!!! DeathGunner132 120 — 6y
Ad

Answer this question