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
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])