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'm trying to make character customization and I'm about done with it but... I need to save the information the player has selected into a DataStore.

This is my code and the error I'm getting is "Cannot store Array in DataStore". I've tried using a for loop to cycle through Value but then it gave me an error saying "Cannot store int in DataStore". I've also tried to cycle through "UpdateStats" but then I remembered that it was a function and not a table. So my question is: How do I fix the error and how does it work so I won't make the same mistake later?

local rep = game:GetService("ReplicatedStorage")
local CharInfo = rep.CharInfo
local DDS = game:GetService("DataStoreService")
local CharInfoDDS = DDS:GetDataStore("CharactInfo")




CharInfo.OnServerEvent:Connect(function(player)
	print("This works lol")
	--Infomation
local BodyColors = workspace.Character.Head.BrickColor
local PrimaryHair = workspace.Character:WaitForChild("PrimaryHair").HairNum.Value
local PriColorHair = workspace.Character:WaitForChild("PrimaryHair").Handle.BrickColor
local PriNeon = workspace.Character:WaitForChild("PrimaryHair").Handle.Material
local SecondaryHair = workspace.Character:WaitForChild("SecondaryHair").HairNum.Value
local SecColorHair = workspace.Character:WaitForChild("SecondaryHair").Handle.BrickColor
local SecNeon = workspace.Character:WaitForChild("SecondaryHair").Handle.Material
local Gender = rep.MaleFemale.Value
local Trait = rep.TraitChoosing.Value
local Spawn = "Outcast Lands"
--End
	local function UpdateStats(Value)
		Value[1] = BodyColors
		Value[2] = PrimaryHair
		Value[3] = PriColorHair
		Value[4] = PriNeon
		Value[5] = SecondaryHair
		Value[6] = SecColorHair
		Value[7] = SecNeon
		Value[8] = Gender
		Value[9] = Trait
		Value[10] = Spawn
		print(BodyColors, game.Workspace.Character.Head.BrickColor)
		for i = 1, #Value do
			print(Value[i])
		end
		return Value
			
	end
	CharInfoDDS:UpdateAsync(player.UserId, UpdateStats)
end)

2 comments

0

You can't save instances to datastores. thats all I know why this error occurs.

0

You can't save instances to datastores. thats all I know why this error occurs.

2 answers

Yeah this can be annoying, but you should be able to get around it by doing something like

local DDS = game:GetService("DataStoreService")
local CharInfoDDS = DDS:GetDataStore("CharactInfo")



--loading
local data = CharInfoDDS:GetAsync("somevalue")
data = game:GetService("HttpService"):JSONDecode(data)

-- saving
local data = {}
game:GetService("HttpService"):JSONEncode(data)
CharInfoDDS:SetAsync("somevalue", data)

This should work out just fine. Please correct me if I'm wrong.

3 comments

0

Well, the reason some people like saving actual tables, is because they are easier to read because we are more familiar. Not saying JSON tables are hard to read, though.

0

Also, you never do anything with the JSON table you encoded.

0

o.o

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