Tween not taking shortest path

  1. What do you want to achieve? Keep it simple and clear!
    I want to create a mount system using tweening.
  2. What is the issue? Include screenshots / videos if possible!
    When rotating, the tween doesn’t take the shortest path, and it doesn’t stop rotating when you stop, until it has reached its goal. (fixed crossed out issue)
    https://streamable.com/5dhkxz
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried to pause the tween, but that does not seem to work.
    Here is my code:
local Seat = script.Parent
local TS = game:GetService("TweenService")
local mbp = script.Parent.Parent.MountBasePart
local moving = false

spawn(function()
	while true do
		wait()
		local ti2 = TweenInfo.new(
			.1
		)
		local t2
		if moving == true then
			local moveto = mbp.Position + mbp.CFrame.LookVector
			print(moveto)
			t2 = TS:Create(mbp, ti2, {Position = moveto})
			t2:Play()
		else

		end
	end
end)

local prevtween

spawn(function()
	while true do
		wait()
		if Seat.Occupant then
			local wd = Vector3.new(Seat.Occupant.MoveDirection.X, 0, Seat.Occupant.MoveDirection.Z)
			local sp = mbp.Position
			local wto = sp + wd
			local mag = (sp - wto).Magnitude
			local ti = TweenInfo.new(
				.5 * mag
			)
			local x, y, z = CFrame.new(sp, sp + wd):ToOrientation()
			local t = TS:Create(mbp, ti, {Orientation = Vector3.new(math.deg(x), math.deg(y), math.deg(z))})
			if Seat.Occupant.MoveDirection ~= Vector3.new(0, 0, 0) then
				

				if moving == true then
					t:Play()
					print("played")
					prevtween = t
				else
					prevtween:Pause()
					print("stopped")
				end
			else
				prevtween:Pause()
				print("stopped")
			end	
		end
	end
end)

local function rotate()
	if Seat.Occupant then
		if Seat.Occupant.MoveDirection ~= Vector3.new(0, 0, 0) then
			moving = true		
		else
			moving = false
		end
	else
		moving = false
	end
end



local function onChanged(property)

	if property == "Steer" then
		rotate()
	elseif property == "Throttle" then
		rotate()
	elseif property == "Occupant" then
		rotate()
	end
end

script.Parent.Changed:Connect(onChanged)

For your tween service it does not know the style do this

local ti2 = TweenInfo.new(
    .1, --Time
    Enum.EasingStyle.Linear, --Style
    Enum.EasingDirection.Out, --Direction
    0, --Repeating
    false, --Reversing on stop
    0 --Delay before start
)

I don’t think you get what I meant…
The tweening works (almost) perfectly.
The only 2 issues that I’m facing is that the tween doesn’t always take the shortest path to its destination and always finishes what it’s doing instead of pausing when I want it to pause.

then try tween:Stop() :grinning_face_with_smiling_eyes:

I have already tried that, and I do not see any difference in using :Pause() and :Stop()
I think I know how to fix that though, so for the moment my main concern is the tween not taking the shortest path.

Pause pauses it in place stop puts you back in the place you started the tween in

Would that not be :Cancel() you are referring to?

Yup. Just as I thought, I fixed one of the issues.
The only issue is that the tween is not taking the shortest path.
I have updated the thread with my current script.

Fixed it by tweening the CFrame instead of the orientation!

1 Like