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

I'm having trouble with a Datastore for saving tables?

local function SaveVariables(Player) local plrStats = Player:WaitForChild("leaderstats") local Prestige = plrStats.Prestige local Level = plrStats.Level local Exp = plrStats.Exp local Guardian = Player:WaitForChild("Guardian") local Outfit = Player:WaitForChild("Outfit") local Quest = Player:WaitForChild("Quest")

local Skill_Folder = Player:WaitForChild("Skills")
local Ab1 = Skill_Folder:WaitForChild("Skill1")
local Ab2 = Skill_Folder:WaitForChild("Skill2")
local Ab3 = Skill_Folder:WaitForChild("Skill3")
local Ab4 = Skill_Folder:WaitForChild("Skill4")
local Ab5 = Skill_Folder:WaitForChild("Skill5")


local pos = 1

local id = Player.UserId

local PlayerTable = {}

table.insert(PlayerTable, 1, Guardian.Value)
table.insert(PlayerTable, 2, Level.Value)
table.insert(PlayerTable, 3, Exp.Value)
table.insert(PlayerTable, 4, Prestige.Value)
table.insert(PlayerTable, 5, Outfit.Value)
table.insert(PlayerTable, 6, Quest.Value)
table.insert(PlayerTable, 7, Ab1.Value)
table.insert(PlayerTable, 8, Ab2.Value)
table.insert(PlayerTable, 9, Ab3.Value)
table.insert(PlayerTable, 10, Ab4.Value)
table.insert(PlayerTable, 11, Ab5.Value)

print(PlayerTable)
PlayerStore:SetAsync(id, PlayerTable)
print(PlayerTable)

end

For some reason the error i get is that -'103: Array is not allowed in data stores' i dont know what im doing wrong

1 answer

You can't save tables to datastores unfortunately, but you can save strings! To convert a table into a string, use HttpService:JSONEncode(). To convert that encoded table into a decoded one, use HttpService:JSONDecode(). Example:

local function SaveVariables(Player) 
	local http = game:GetService("HttpService")
	local plrStats = Player:WaitForChild("leaderstats")
	local Prestige = plrStats.Prestige
	local Level = plrStats.Level 
	local Exp = plrStats.Exp 
	local Guardian = Player:WaitForChild("Guardian") 
	local Outfit = Player:WaitForChild("Outfit")
	local Quest = Player:WaitForChild("Quest")
	local Skill_Folder = Player:WaitForChild("Skills")
	local Ab1 = Skill_Folder:WaitForChild("Skill1")
	local Ab2 = Skill_Folder:WaitForChild("Skill2")
	local Ab3 = Skill_Folder:WaitForChild("Skill3")
	local Ab4 = Skill_Folder:WaitForChild("Skill4")
	local Ab5 = Skill_Folder:WaitForChild("Skill5")

	local pos = 1

	local id = Player.UserId

	local PlayerTable = {}

	table.insert(PlayerTable, 1, Guardian.Value)
	table.insert(PlayerTable, 2, Level.Value)
	table.insert(PlayerTable, 3, Exp.Value)
	table.insert(PlayerTable, 4, Prestige.Value)
	table.insert(PlayerTable, 5, Outfit.Value)
	table.insert(PlayerTable, 6, Quest.Value)
	table.insert(PlayerTable, 7, Ab1.Value)
	table.insert(PlayerTable, 8, Ab2.Value)
	table.insert(PlayerTable, 9, Ab3.Value)
	table.insert(PlayerTable, 10, Ab4.Value)
	table.insert(PlayerTable, 11, Ab5.Value)

	local success, err = pcall(function() -- pcall just in case an error occurs
		PlayerStore:SetAsync(id, http:JSONEncode(PlayerTable)) -- Encode into a string, http:JSONDecode() to convert back into a table
	end)
	
	if not success then
		warn(err)
		return
	end

end

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