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”?
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
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.
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.