Tweening CFrame changes orientation of part

I’m trying to tween the position of a part from point 1 to point 2 then back to point 1 and so forth.

The problem is that when I try to Tween the CFrame, the Orientation also gets Tweened to 0,0,0 which I do not want.

This is probably a very easy fix but I can’t figure it out

local part = script.Parent	

local ts = game:GetService("TweenService")

while true do
	local tweeninfo1 = TweenInfo.new(
		4,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.InOut,
		0,
		false,
		0
	)
	local tween0 = ts:Create(
		part,
		tweeninfo1,
		{CFrame = CFrame.new(-405.469, 29.518, -200.444)}
	)
	tween0:Play()
	part.Orientation = Vector3.new(0,-90,0)  --This is the value it needs to stay but this doesn't help, only stays like this for a short period
	tween0.Completed:Wait()
	local tween1 = ts:Create(
		part,
		tweeninfo1,
		{CFrame = CFrame.new(-362.469, 29.518, -200.444)}		
	)
	tween1:Play()
	tween1.Completed:Wait()
end

Just tween the position instead of CFrame if you don’t want to change the orientation

1 Like

How did I not figure that out haha. Thanks for the help!

Kinda funny really. Anyway the reason it changes orientation is probably because you didn’t supply a custom orientation to CFrame.new(), so it will take orientation as 0,0,0

1 Like

Yea I was also stunned by this since I’ve always used CFrame to change the position something is in, however I’ve never used Tween service for changing someones position until now it. Still new to scripting so mistakes are to be made haha.

1 Like

CFrame is two value the position and where it will be facing

Example 1:
CFrame

CFrame.new(Vector3.new(1, 2, 3), Vector3.new(1, 2, 3),)

  • the first vector is the position and the second vector is orientation
    Note: Use CFrame if you want to manipulate the part’s Position and Orientation

Example 2:
Position

Part.Position = Vector3.new(1, 2, 3)

  • this only can manipulate the position of a part
    Note: Use this if you only want to change the position

Overall you could use:

  • Position
    TweenService:Create(Part, TweenInfo(1), {Position = Vector3.new(1, 2, 3)}):Play()

  • CFrame
    TweenService:Create(Part, TweenInfo(1), {CFrame = CFrame.new(Vector3.new(1, 2, 3), Vector3.new(1, 2, 3))}):Play()

1 Like

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