Get table coordinates into CFrame

I’m storing the rotation of a part using individual numbers, based on the CFrame, however when I try reloading the blocks rotation, I get an invalid arguments error.

local function TableToCframe(tab)
    print(tab)
	return CFrame.new(unpack(tab))
end

NewCFrame = CFrame.new(position) * TableToCframe(rotationCFrame)

I ONLY save the rotation data of the CFrame. So I only want to get the last 9 numbers of a CFrame (NOT THE FIRST 3, being position)

21:15:20.930   ▼  {
                    [1] = "0",
                    [2] = "0",
                    [3] = "0",
                    [4] = "0",
                    [5] = "0",
                    [6] = "1",
                    [7] = "0",
                    [8] = "1",
                    [9] = "0"
                 }  
  21:15:20.930  Invalid number of arguments: 9 

Just pass the first 3 arguments as 0s so when you combine 2 CFrames, position doesn’t get changed:

local function TableToCframe(tab)
    print(tab)
    return CFrame.new(0, 0, 0, unpack(tab))
end

I tried that too, and it sent the block to these coords
0, -340282346638528859811704183484516925440, 0

Well then there is something wrong with your position data. Can you try to print position variable in console please?

local function TableToCframe(tab)
	return CFrame.new(0, 0, 0, unpack(tab))
end

local ConvertedCFrame = TableToCframe(rotationCFrame)
print(position, ConvertedCFrame)
NewCFrame = CFrame.new(position) * ConvertedCFrame

With your Rotation numbers, one of the rotation vectors is (0, 0, 0). When you just print the CFrame, it looks okay. However, if you set part.CFrame to be that CFrame and print part.CFrame, you’ll notice that the directional part of the CFrame turns into NAN, NAN, … . Every direction vector should be a unit vector, not a vector with length 0.

1 Like

I’m unsure what you mean???

1 Like

Every CFrame should have a position and three perpendicular unit vectors that represent its rotation. A unit vector is a vector with length 1.

Your table contains these numbers for the rotation:
0, 0, 0, 0, 0, 1, 0, 1, 0

I’m not sure in what order the constructor puts the numbers into the vectors, but if you only have two numbers that are ~= 0, then there can only be a number different than 0 in two of the three direction vectors. This means that one of the direction vectors is (0, 0, 0).

When a CFrame with invalid rotation data is put to a part, its rotation will be NAN (and, for some reason, the property window shows that strange position).

To expand on what he said, all a cframe is in this context is a look at matrix. remember that with identity matrices when a 4x4 vector is its identity it acts as a basis for all vector transformations. if you multiply this by a vector for example nothing will happen to it cause its the identity matrix. however, if you change the values such they are unit vectors perpendicular to each other what essentially you are doing is changing the origin of this world in example. So say I got a point at 0,2,0 and my look at is defined as vector a, vector b, normalize(cross(vector b, vector a)). Depending on how my vectors are stored vector a will be the positive x axis, vector b is the positive y axis and vector c is the front axis.
BTW: The reason they are negative Px and stuff is due to how the opengl coordinate system works

How’s it invalid though?? Unless I’m saving it wrong??

With those numbers, one of the rotation vectors has length 0. Changing the first of the nine rotation numbers to 1 will probably fix the problem.

Well I get the values by

local Rotation = CFrameToTable(block.CFrame - block.CFrame.Position)

and store as a string with “_” seperating the numbers, then convert back. So I don’t see how or why it’s wrong

Can you show the CFrameToTable function?

local function CFrameToTable(cFrame)
	return {cFrame:GetComponents()}
end

What is wrong with this? The printed CFrame looks okay except for the missing vector as they mentioned, but the positional part of the CFrame is 0,0,0 as I thought you wanted.

Read the rest of the discussion, I’ve tried that

But with what code do you store only the nine last numbers? Doesn’t CFrameToTable put the position into the table too? Are you sure that the table you printed has the nine rotation numbers and not the position and six rotation numbers?

Should be only rotation numbers?

local Rotation = CFrameToTable(block.CFrame - block.CFrame.Position)

That CFrame should be CFrame - CFrame.Position (and thus only be the 9 rotation values?)

You said that you want

so instead your function should be

local function CFrameToTable(cFrame)
	cFrame = {cFrame:GetComponents()}
	for i=1, 3 do
		table.remove(cFrame, i)
	end

	return cFrame
end

I did, it looks to me like you guys are chasing a separate issue though. If the block is appearing in the middle of nowhere, it is not the fault of the CFrame.