How do i save a table

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to be able to save tables, when i do this it keeps throwing errors.

  2. What is the issue? Error: https://gyazo.com/4cee1810e37aa27eeec5541126c323c5 Serializer Code: https://gyazo.com/76da4ffb6dd701f9f5e994496642149e

  3. What solutions have you tried so far? Ive been looking alot for the past half hour but everything i trys errors or doesnt work.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local mod = require(game.ServerScriptService.Serializer)
local HttpService = game:GetService("HttpService")
local seriz = {}
local dss = game:GetService("DataStoreService")
local store = dss:GetDataStore("ObjectData")

game.ReplicatedStorage.save.OnServerEvent:Connect(function(p)
	seriz = {}
	for _,v in pairs(game.Workspace.House.Serializes:GetChildren()) do
		table.insert(seriz,mod.Serialize(v,false))
	end
	for _,i in pairs(game.Workspace.House.Serializes:GetChildren()) do
		wait(0.25)
		i:Destroy()
	end
	local s,e = pcall(function()
		store:SetAsync(p.UserId,HttpService:JSONEncode(seriz))
	end)
	if s then
	else
		error(e)
	end
end)

game.ReplicatedStorage.load.OnServerEvent:Connect(function(p)
	local tableGot
	local s,e = pcall(function()
		tableGot = store:GetAsync(p.UserId)
	end)
	local decodedTable = HttpService:JSONDecode(tableGot)
	if s then
		for _,v in pairs(decodedTable) do
			mod.UnSerialize(HttpService:JSONDecode(v))
		end
	else
		error(e)
	end
	seriz = {}
end)
for _,v in pairs(decodedTable) do
			mod.UnSerialize(HttpService:JSONDecode(v))
		end

What are you expecting ‘v’ to be? A table?
In your unserialize function check to see if tab isn’t empty. It looks like your :FindFirstChild() call is erroring because you are passing it a nil value.

Mhm im expecting v to be a table, since the serialized object is in a table so i put that table into the “Main table” then i want to save the main table, let me test what you said. but can you explain what you mean by “Check to see if tab is empty”?

I just looked and i dont need to decode the second table but when i dont i get another error: https://gyazo.com/2d84cae2de8ec7f7039ede2ecd812fd1

Alr i printed out everything in the new table and it only has 2 values: 1,true
so ItemId: 1
and
pos: true
i think thats why its error… but why is that true

Alr this is what im getting: https://gyazo.com/afc9a6a698d3703bf335bfba6df5f258

Does your table have string and number keys?

it has vector3 values bool values number values

this is the values it uses

	local itemID = object.ItemId.Value
	local pos = object.Position
	local ori = object.Orientation
	local name = object.Name
	local parent = object.Parent
	local anchored = object.Anchored

Cancel that I see the problem, its because you are trying to vector3 values I believe. You can’t encode anything thats a roblox type. It has to be regular Lua types or else itll decode out as nil.

damn, is there anyway i can combat that or is there any other way?

AFK 30 charssssssssssssssssssssssssssssssssssssssss

You can encode the raw number values and then reconstruct them back into a Vector3 after a decode.

Ok let me try that 30 charsssssssss

How would i convert a object into something it can encode?

i remade the serialize and un serialize with what you said

local module = {}
function module.Serialize(object,des)
	local itemID = object.ItemId.Value
	local pos = {["X"]=object.Position.X,["Y"]=object.Position.Y,["Z"]=object.Position.Z}
	local ori = {["X"]=object.Orientation.X,["Y"]=object.Orientation.Y,["Z"]=object.Orientation.Z}
	local name = object.Name
	local parent = object.Parent
	local anchored = object.Anchored
	if des == true then
		object:Destroy()
	end
	return {itemID,pos,ori,name,parent,anchored}
end
function module.UnSerialize(tab)
	local ItemId = tab[1]
	local pos = tab[2]
	local ori = tab[3]
	local name = tab[4]
	local parent = tab[5]
	local anc = tab[6]
	local Object = game.ServerStorage.Items:FindFirstChild(ItemId):Clone()
	Object.Position = Vector3.new(pos.X,pos.Y,pos.Z)
	Object.Orientation = Vector3.new(ori.X,ori.Y,ori.Z)
	Object.Anchored = anc
	Object.Name = name
	Object.Parent = parent
	print("Object Un Serialized, should appear in original position.")
end
return module

What do you mean by an “object” ? You mean an instance? Like a part? You’d need to store the values of all of the important properties then when you load the data you recreate the part using the data from the store.