How to get the Rotation of something?

Hello, I’m trying to get the X,Y,Z orientation of a model. I though that doing:

clone:GetPivot().Rotation

However this prints:

0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1

when I try to do

clone:GetPivot().Rotation.X

its always 0. (all same with X,Y,Z)

1 Like
local x,y,z = clone:GetPivot():ToOrientation()
print(math.deg(x),math.deg(y), math.deg(z))
2 Likes

Rotation

CFrame

A copy of the CFrame with no translation.

The X Y Z of .Rotation is the position value which is 0.

The rotation part is 9 numbers after the x,y,z components

1 Like

This is the identity matrix which is what roblox counts as 0, 0, 0 rotation. @dthecoolest probably has the closest to what you want, but it depends on what you want this rotation for. Its possible you only need a direction not a CFrame.

Also I believe you’ll only get a reasonable rotation for a model if its primary part is set, so make sure it is.

so I did:

table.insert(Info.Plot, {
			["Object"] = child.Name,
			["X"] = clone:GetPivot().Position.X - child:GetPivot().Position.X,
			["Z"] = clone:GetPivot().Position.Z - child:GetPivot().Position.Z,
			["Rotation"] = {
				["X"] = clone:GetPivot():ToOrientation().X,
				["Y"] = clone:GetPivot():ToOrientation().Y,
				["Z"] = clone:GetPivot():ToOrientation().Z
			}
		})

to save the parts

when I load the data I am doing:

for i,v in pairs(Info.Plot) do
		local PlotInfo = nil
		for i,Build in pairs(AllBuilds) do
			if v.Object == Build.Name then
				PlotInfo = Build:Clone()
			end
		end
		PlotInfo.Parent = clone.Data 
		local X = clone:GetPivot().Position.X + v.X
		local Z = clone:GetPivot().Position.Z + v.Z

		PlotInfo:PivotTo(CFrame.new(Vector3.new(X,15.1,Z)) * CFrame.Angles(math.deg(v.Rotation.X), math.deg(v.Rotation.Y), math.deg(v.Rotation.Z)))
	end

However the part isnt showing up

The model only started not showing up after I used your

Cframe:ToOrientation()

before that it was teleporting it to the correct position but not rotating it

ERROR:
Workspace.Plots.Script:189: attempt to index number with ‘X’

I said this

I did not say this:

Try again with my part of the code which will not error.

The function specifically outputs a tuple which needs a comma to get the x, y, z value.

table.insert(Info.Plot, {
			["Object"] = child.Name,
			["X"] = clone:GetPivot().Position.X - child:GetPivot().Position.X,
			["Z"] = clone:GetPivot().Position.Z - child:GetPivot().Position.Z,
			["Rotation"] = {
				["X"] = math.deg(x),
				["Y"] = math.deg(y),
				["Z"] = math.deg(z)
			}
		})

and

	for i,v in pairs(Info.Plot) do
		local PlotInfo = nil
		for i,Build in pairs(AllBuilds) do
			if v.Object == Build.Name then
				PlotInfo = Build:Clone()
			end
		end
		PlotInfo.Parent = clone.Data 
		local X = clone:GetPivot().Position.X + v.X
		local Z = clone:GetPivot().Position.Z + v.Z

		PlotInfo:PivotTo(CFrame.new(Vector3.new(X,15.1,Z)) * CFrame.Angles(math.rad(v.Rotation.X), math.rad(v.Rotation.Y), math.rad(v.Rotation.Z)))
	end

do this:

local x,y,z = clone:GetPivot():ToOrientation()
table.insert(Info.Plot, {
			["Object"] = child.Name,
			["X"] = clone:GetPivot().Position.X - child:GetPivot().Position.X,
			["Z"] = clone:GetPivot().Position.Z - child:GetPivot().Position.Z,
			["Rotation"] = {
				["X"] = math.deg(x),
				["Y"] = math.deg(y),
				["Z"] = math.deg(z)
			}
		})

Or you can do this if you pack the tuple

table.insert(Info.Plot, {
			["Object"] = child.Name,
			["X"] = clone:GetPivot().Position.X - child:GetPivot().Position.X,
			["Z"] = clone:GetPivot().Position.Z - child:GetPivot().Position.Z,
			["Rotation"] = {
				["X"] = math.deg({clone:GetPivot():ToOrientation()}[1]),
				["Y"] = math.deg({clone:GetPivot():ToOrientation()}[2]),
				["Z"] = math.deg({clone:GetPivot():ToOrientation()}[3])
			}
		})

is it okay i convert it to math.rad when I do

CFRAME.ANGLES()

Oh whoops forgot the convert to radians for the packed tuple example, I’ll edit the post.

Also

Use CFrame.fromOrientation instead

Okay so BOTH

local x,y,z = clone:GetPivot():ToOrientation()
print("(".. x .. ", " .. y .. ", " .. z .. ")")

AND

print(clone:GetPivot():ToOrientation())

always prints
(-0, 0, 0)

Then there is something wrong with your clone model and its pivot.

You should probably parent it to workspace and see the properties and see the issue further.

Otherwise I got insufficient information seems to work fine for a normal part in a model.

Hello I am pivoting a model not a part inside of a model. also the part thats not working

IS NOT SETTING THE ORIENTATION but getting it.

when I do

print(clone:GetPivot():ToOrientation())

it prints 0,0,0.
not to mention that scripts work differently than manually editting the property in studios

1 Like

I am unable to help you further, this is a it works for me but not for you scenario.

Send a repro file if you wish to diagnose the full problem accounting for each variable and such.

I would suggest trying to do what you are doing in a new baseplate to see if there are some other factors affecting the scenario.

I believe you do not know what to do and that you do not sufficiently understand my problem. You are manually changing the orientation of a part inside of a model in the properties tab. Thank you for your attempt but I believe this issue is too much for you

That is true it is a bit too much for me when you don’t convey your problem accurately.

For my model it is able to print out the orientation accurately in radians and in play tests when I run the game.

Anyways good luck with your problem.

Edit: NVM found out it is due to needing a primary part for your model see the other post you made. Apologies for the inconvenience, although that is normal in the journey to find a solution.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.