Tween doesn't work when playtesting

I’ve created a function to make the players camera spin around a pivot part. I’ve playtested multiple times over the last few days. In some cases, it would work perfectly fine, but in all the others, it would do the exact opposite of what I want. This is what it looks like when it doesn’t work:

The spin is supposed go 360°, but as you can see, it stops halfway and does that weird thing where it moves the camera to the player and then goes back to the pivot part (the part that you see while the tween is playing only there to make sure it’s moving).

Here’s the full script:

--Get TweenService
local TweenService = game:GetService('TweenService')

--Make Camera Scriptable
local cam = workspace.CurrentCamera
wait(0.01)
cam.CameraType = Enum.CameraType.Scriptable

--Define Camera Pivot
local pivot = workspace.CameraPivot

--Rotation Function 1
local function rotation1()
	--Set Camera Position 1
	cam.CFrame = pivot.CFrame * CFrame.Angles(0, math.rad(180), 0)
	
	--Make Tween 1
	local tweenInfo = TweenInfo.new(
		30,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.In,
		0,
		false
	)
	local goal1 = {CFrame = pivot.CFrame * CFrame.Angles(0, math.rad(360), 0)}
	local anim1 = TweenService:Create(cam, tweenInfo, goal1)
	
	--Rotation Function 2
	local function rotation2()
		--Set Camera Position 2
		cam.CFrame = pivot.CFrame

		--Make Tween 2
		local tweenInfo = TweenInfo.new(
			30,
			Enum.EasingStyle.Linear,
			Enum.EasingDirection.In,
			0,
			false
		)
		local goal2 = {CFrame = pivot.CFrame * CFrame.Angles(0, math.rad(180), 0)}
		local anim2 = TweenService:Create(cam, tweenInfo, goal2)

		--Play Tween 2
		anim2:Play()
		wait(0.01)
	end
	
	--Play Tween 1
	anim1:Play()
	anim1.Completed:Connect(rotation2)
end

while true do
	rotation1()
	wait(60.0)
end

I used to think that there wasn’t any problem with it since it sometimes works, but now I’m starting to doubt myself. Anybody know anything about this?

There is a syntax error in the last line of the code. end. should be end. Removing the period should fix the issue.

I checked all of my end statements and I don’t see any periods? The problem is probably somewhere else.
Apart from that, I have playtested the game again. Out of 10, attempts 4, 5, 8 and 9 did not work. There doesn’t seem to be a pattern to this.

It seems that the problem might be due to how you are structuring the rotation functions. When the first tween completes, it calls the second rotation function but then immediately goes back to the first rotation function and starts the second tween which then causes the awkward movement.

One solution would be to use a while loop to continuously rotate the camera, as opposed to using a function that calls another function after the first tween completes. Here’s what the modified code might look like:

–Get TweenService
local TweenService = game:GetService(‘TweenService’)

–Make Camera Scriptable
local cam = workspace.CurrentCamera
wait(0.01)
cam.CameraType = Enum.CameraType.Scriptable

–Define Camera Pivot
local pivot = workspace.CameraPivot

while true do
–Set Camera Position 1
cam.CFrame = pivot.CFrame * CFrame.Angles(0, math.rad(180), 0)

--Make Tween 1
local tweenInfo = TweenInfo.new(
	30,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	true
)
local goal1 = {CFrame = pivot.CFrame * CFrame.Angles(0, math.rad(540), 0)}
local anim1 = TweenService:Create(cam, tweenInfo, goal1)

--Play Tween 1
anim1:Play()
wait(30)

--Reset Camera Position
cam.CFrame = pivot.CFrame

--Wait 30 seconds before next rotation
wait(30)

end

The thing about Roblox tweens is that they try to find the quickest way to get to the goal, so adding 540° doesn’t change its position. I tried it with 360° instead and the original problem appeared again after the it repeated once. I understand what you’re trying to do, but it is for this exact reason that I’m using two tweens. Maybe it’s a problem with the camera’s position not resetting properly?