How can I use the orientation value from a block to set the CFrame orientation?

Hello friendly people of the DevForum!

As some of you might know, I’m making a game that needs to spawn certain vehicles in various different positions. Of course I do not want all vehicles pointing into one direction, which is why I have been trying out various different commands to put into the command line that plays around with the CFrame of a vehicle model.

However, every time I tried using an orientation in a CFrame Code, it led to unexpected results.
My problem is that I can not use an orientation from a random part to rotate the model.

The forum didn’t help, as basically every rotation is included with fixed parameters, e.g.

CFrame.Angles(x,y,z) -- x,y,z can be replaced by any integer.

I tried using the following command to rotate my model, however it didn’t work as expected:

game.Workspace.Model:SetPrimaryPartCFrame(CFrame.new(game.Workspace.test.Position)*CFrame.Angles(workspace.testPart.Orientation))

Thanks for the answers in advance,
(sadly not the real) Brendon aka xxMVG_Fan8xx

Are you sure that all the parts of the model are welded to the PrimaryPart?

1 Like

If your parts are welded (as noted above), also check your line of code. You are using “test” for Position and “testPart” for orientation. Are those supposed to be two parts? Can look at using PivotTo instead of setting the PrimaryPart directly. Can also use Rotation property of a CFrame as I did here:

game.Workspace.Model:PivotTo(CFrame.new(game.Workspace.testPart:GetPivot().Position)*workspace.testPart.CFrame.Rotation)

1 Like
CFrame.Angles(math.rad(Part.Orientation.X), math.rad(Part.Orientation.Y), math.rad(Part.Orientation.Z))
1 Like

CFrame.Angles applies the rotation in XYZ order. Basepart.Orientation has the rotation in YXZ order so you would use CFrame.fromOrientation instead, unless OP actually wants to use CFrame.Angles.

CFrame.fromOrientation(math.rad(Part.Orientation.X), math.rad(Part.Orientation.Y), math.rad(Part.Orientation.Z))
1 Like
CFrame.Angles(workspace.testPart.Orientation)

Looking at this, I assumed they just wanted to pass the orientation value’s components directly into the CFrame.Angles() constructor, in the same order in which the axis are defined (X, Y, Z).

1 Like

Yes, otherwise the model would not teleport in the first place, would it?

That’s a mistake that I corrected in the cmd line, however, forgot to correct here in the forum. It’s supposed to be one part.

Alright, I ran this command you provided and it worked.

Thanks for the help everyone! I acknowledged all of your suggestions from those who replied below Astr0, however, this script provided worked.

1 Like