Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Cannot store Array in DataStore?

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

2 comments

1

Color3 values cannot be saved. You need to save each part of a Color3 separately.

0

Lol i just thought about that before I refreshed the page

1 answer

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

2 comments

0

This is a great way of doing this; great job!

0

THANK YOUUUUUUUUUUUUUUUUUUUUUUUUUUUU!!!!!!!!!!!!!!!!!!!!!!!!

This discussion is preserved as it was. New answers, comments, and votes are closed.