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.

01local PSavedData = PrimaryDataStore:GetAsync(id)
02if PSavedData then
03    PTransparency.Value = PSavedData[1]
04    PLocalColor.Value = PSavedData[2]
05    PMeshId.Value = PSavedData[3]
06    PMeshTextureId.Value = PSavedData[4]
07    PPETextureId.Value = PSavedData[5]
08    PSpread.Value = PSavedData[6]
09    PPELocked.Value = PSavedData[7]
10else
11local PDataForSaving = {
12        PTransparency.Value,
13        PLocalColor.Value,
14        PMeshId.Value,
15        PMeshTextureId.Value,
View all 21 lines...
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 4 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.

1local NewTable = {PARTNAME.Color.r,PARTNAME.Color.g,PARTNAME.b}
2local JSONTable = game:GetService("HttpService"):JSONEncode(NewTable)
3PrimaryDataStore:SetAsync(id, JSONTable)
4--In order to load the color we saved we can do something like this--
5local ColorTable = PrimaryDataStore:GetAsync(id)
6local DecodedTable = game:GetService("HttpService"):JSONDecode(Color3Table)
7local 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