Struggling to make model face same direction as another model

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?

I want the back bogey of my carriage to face the same direction as the front bogey.

  1. What is the issue? Include screenshots / videos if possible!

With the code I have developed, the back bogey faces about 45 degrees away from where the front bogey is pointing towards. It should be near -1 considering its intial position for x axis orientation like the front bogey but that is not happening for the back.

Here are some screenshots:


As can be seen here, front is standard. The Back is supposed to copy the front orientation. The front bogey has gliders unlike the back, which gives the front reliable guidance on rails. The back needs to rely on the orientation of the front, since the back does not have gliders (long story as to why I coudn’t put gliders on back as well). So basically the back bogey has wheels and just stabilizes the back of the train.


However, the back as seen here, is not following the orientation of the front and is facing away from the rails.

Here is the code which operates the CFrame to copy the orientation fo the front bogey for the back. I struggled with this code and getting models to orientate since it seems like CFrame cannot be directly used on models but instead primary parts.

local part1 = script.Parent.Parent.Parent.Bogey.Back --this is a model
local part2 = script.Parent.Parent.Parent.Bogey.Front.CFramePart --this is a part
part1:SetPrimaryPartCFrame(CFrame.new(part1.CFramePart.Position, part2.CFrame.LookVector))

It may also be a building issue, since the orientations in the transform section of properties do not match. Back is 0, 90, 0 and front is 0, 0, 0, as pictured below.


  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I literally have been experimenting with this and looking at the developer hub for hours. I am a noob with CFrame.

Any help would be appreciated!

local X, Y, Z = Part2.CFrame:ToEulerAnglesXYZ();
Part1.CFrame = CFrame.new(Part1.Position) * CFrame.Angle(X, Y, Z);
2 Likes

Was returned an error “Position is not a valid member of Model “Workspace.3000Series8Car.Train.Carriage1-2.Carriage1.Bogey.Back”” :frowning:

Part1 should be the primarypart of the model

local part1 = script.Parent.Parent.Parent.Bogey.Back.CFramePart
local part2 = script.Parent.Parent.Parent.Bogey.Front.CFramePart
local X, Y, Z = part2.CFrame:ToEulerAnglesXYZ();
part1.CFrame = CFrame.new(part1.Position) * CFrame.Angle(X, Y, Z);

Made “local part1” into the primarypart of the model. Am getting a different error this time:
Workspace.3000Series8Car.Train.Carriage1-2.Carriage1.Body.VehicleSeat.Script:33: attempt to call a nil value

what’s on line 33? the change you made may have affected some other parts of your script

also instead of doing

local part1 = script.Parent.Parent.Parent.Bogey.Back.CFramePart

try this

local part1 = script:FindFirstAncestor("Bogey").Back.PrimaryPart;
1 Like

This would not work in this case, since it predictably returned a nil value. I am confused abot the nil value at line 33 which I am trying to figure out:

part1.CFrame = CFrame.new(part1.Position) * CFrame.Angle(X, Y, Z)

okay I found out what was wrong, it was Angles not Angle try changing that

1 Like

Sir, thank you so much for fixing the fundamental issue I was having :slight_smile:

Since it was a model, it left behind the wheels in the model and only moved the primarypart, due to the expression being only for “part1.CFrame = …”

However, I found a way to bring the whole model along with the primarypart!

local part1 = script.Parent.Parent.Parent.Bogey.Back.CFramePart
	local part2 = script.Parent.Parent.Parent.Bogey.Front.CFramePart
	local model = script.Parent.Parent.Parent.Bogey.Back
	local X, Y, Z = part2.CFrame:ToEulerAnglesXYZ()
	local CFrameInitiate = CFrame.new(part1.Position) * CFrame.Angles(X, Y, Z)
	model:SetPrimaryPartCFrame(CFrameInitiate)