Trying to implement saving into Zblock's Placement System but I cant seem to do it

Alright, So I printed out the entire return of GetComponents and I get:

22.389991760254 2.1449809074402 1.4000090360641 1 0 0 0 1 0 0 0 1

Using this:

nameOfCFrame = {
x = CFrame.x,
y = CFrame.y,
z = CFrame.z,
-- Any other values
}

I believe you could just do:

CFrame.new(nameOfCFrame.x,nameOfCFrame.y,nameOfCFrame.z,any other values) 

This would be for when you want to turn the data back into a CFrame to be used and set the CFrame of whichever model is needed.

Yeah but how would I link the CFrame values with the actual model I want to load in?

Well if you have a Primary Part on the model:
Model:SetPrimaryPartCFrame(CFrameValue)

No not that, when saving the CFrame values in a seperate dictionary how do I know which CFrame corresponds to the right model when I want to load it?

Sorry, I didn’t understand. You could do this:

nameOfCFrame = {
    ModelName = Model.Name
    x = CFrame.x,
    y = CFrame.y,
    z = CFrame.z,
    -- Any other values
}

then when loading:

local Model = WhereYouKeepTheModels:FindFirstChild(nameOfCFrame.ModelName)
local NewCFrame = CFrame.new(nameOfCFrame.x,nameOfCFrame.y,nameOfCFrame.z,any other values) 
Model:SetPrimaryPartCFrame(NewCFrame)

I understand you withdrew your post but I just wanted to clarify.

My example would be used in a system such as this where you would loop through all the models currently added.

 Table[1] = {
    ModelName = Model.Name
    x = CFrame.x,
    y = CFrame.y,
    z = CFrame.z,
    -- Any other values
}

Then Table[2] would be model 2.

Anyway hope this helps! :+1:

1 Like

Sorry I am new to Dictionaries and CFrames.

I also want to store rotations and I can’t just get it from X,Y,Z
So how would I write the rotation values from CFrame into the dictionary.

Sorry this will be extremely tedious to do with my current example instead do CFrame:GetComponents() if your looking to save all of the CFrames values.

It can be used like this:

 Table[1] = {
    ModelName = Model.Name
    CFrameUnpacked = CFrameValue:GetComponents()
    -- Any other values
}

and turning it back into CFrame would be as easy as:

CFrameValue = CFrame.new(CFrameUnpacked)

Just so I am on the same page,

What do you mean by CFrameUnpacked and you did Table[1] = { how would I make change the ‘1’ etc, and where should I put it.

Like for example,

I have this Serialization Function:

function M.Serialize()
local serial = {}

	local ItemHolder = workspace.Plots.Plot.ItemHolder
	
	for i,v in pairs(ItemHolder:GetChildren()) do
		serial["x"] = v.PrimaryPart.CFrame.X
		serial["y"] = v.PrimaryPart.CFrame.Y
		serial["z"] = v.PrimaryPart.CFrame.Z
	end
	return serial
end

Which of course currently does not work, but how would I implement your example into my system.

TL;DR How would I implement your system. Can you be more specific?

And I am sorry if I am not understanding.

When you want to save the data:

function PlaceInTable()
     local Table = {}
     local ItemHolder = workspace.Plots.Plot.ItemHolder
     for i,v in pairs(ItemHolder:GetChildren()) do
          Table[i] = {
               ModelName = v.Name
               CFrameNew = v.PrimaryPart.CFrame:GetComponents()
          }
     end
     return Table
end

Then save the table and unpack the data like this:

function Unpack(Table)
     for i,v in pairs(Table) do
         local Model = PlaceWhereModelsAreHeld:FindFirstChild(Table[i].ModelName)
         Model.Parent = workspace
         Model:SetPrimaryPartCFrame(CFrame.new(Table[i].CFrameNew)
     end
end

Keep in mind: None of this is tested so you may have to make some edits.
Goodluck :joy: :+1:

1 Like

No need to reply anymore I fixed it.

So I went to Eggmoose’s Placement system and checked the deserialization function and the serialization function, and I successfully made it work.

This script worked:

local M = {}
local HTTP = game:GetService("HttpService")

function M.Serialize()
	local serial = {}
	
	local ItemHolder = workspace.Plots.Plot.ItemHolder
	
	local cfi = workspace.Plots.Plot.Plot.CFrame:Inverse()
	local children = ItemHolder:GetChildren()
	
	for i = 1, #children do
		serial[tostring(cfi * children[i].PrimaryPart.CFrame)] = children[i].Name
	end
	
	return serial
end

function M.deSerialize(canvasPart, data)
	local canvasCF = workspace.Plots.Plot.Plot.CFrame
	data = data or {}
	
	for cf, name in pairs(data) do
		local model = game.ReplicatedStorage.Models:FindFirstChild(name)
		if (model) then
			local components = {}
			for num in string.gmatch(cf, "[^%s,]+") do
				components[#components+1] = tonumber(num)
			end
			
			local NewModel = model:Clone()
			NewModel.Parent = workspace.Plots.Plot.ItemHolder
			NewModel:SetPrimaryPartCFrame(canvasCF * CFrame.new(unpack(components)))
		end
	end
end

return M
2 Likes

Great glad its working for you, if you want to learn how to make the method you were originally going to use work I posted the solution that would work for you. :smile: