Issue with CFrame tween

So, I have a part. (Part1) and I want it to in the first tween here: Rotate itself via CFrame and face towards (Part2)

Once it does that, in the second tween. It will both rotate and move towards Part2. Currently, for some reason the first tween rotation doesn’t work. But in the second tween the Rotation and position works correctly as can be seen here:
https://gyazo.com/a11d6903e6607f4f2db9498bc68f99c7

(It plays the first tween of rotation only, barely moves and the second tween plays and it rotates and moves)

So I’m not sure why the rotation bit doesn’t work.

wait(3)

local tweenService = game:GetService("TweenService")

local part1 = script.Parent
local part2 = game.Workspace.FacePart -- The part that part1 will face
local rotation = CFrame.lookAt(part1.Part.Position, part2.Position)
local x,y,z = rotation:toEulerAnglesYXZ()
local goal = part1.Part.CFrame * CFrame.fromEulerAnglesXYZ(0, y , 0)
local info = TweenInfo.new(4, Enum.EasingStyle.Linear) -- Tween for 4 seconds with linear easing
local tween = tweenService:Create(part1.Part, info, {CFrame = goal})
tween:Play() -- the rotation only tween

tween.Completed:Connect(function()
local goal = (part2.CFrame + Vector3.new(0,part1.Part.CFrame.Y,0)) * CFrame.fromEulerAnglesXYZ(0, y, 0)
local info = TweenInfo.new(4, Enum.EasingStyle.Linear) -- Tween for 4 seconds with linear easing
local tween = tweenService:Create(part1.Part, info, {CFrame = goal})
tween:Play() -- the rotation + position CFrame tween
end)
1 Like

This looks problematic to me; the rotation is global but yet you’re using it to “increment” the CFrame rather than setting it to that rotation.
Try doing this instead (also a lot simpler):

local part1Pos = part1.Part.Position
local part2Pos = part2.Part.Position
--note that the Y component is part1 instead of part2!!!
local goal = CFrame.lookAt(part1Pos, Vector3.new(part2Pos.X, part1Pos.Y, part2Pos.Z))