Check when tween stops to break while loop

Hello!

I’m working on a script that tweens the player’s camera until a certain point. What I’m currently using to move it is to use a while loop. However, I don’t know how to break this loop when the tween ends.

How can I check when the tween ends so I can break this while loop?

Script below

local TweenService = game:GetService("TweenService")

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local camera = workspace.CurrentCamera

repeat wait()
	camera.CameraType = Enum.CameraType.Scriptable
until camera.CameraType == Enum.CameraType.Scriptable

local cameraFolder = workspace:WaitForChild("Cameras")
	local camera1 = cameraFolder:WaitForChild("CameraPart1")

local TweeningInformation = TweenInfo.new(
	1.5, -- Duration
	Enum.EasingStyle.Sine, -- Easing style
	Enum.EasingDirection.Out, -- Easing direction
	0, -- Times repeated
	false, -- Should tween repeat
	0 -- Delay between tween
)

local PartProperties = {
	Position = Vector3.new(-86.5, 4.625, -166.725)
}

local Tween = TweenService:Create(camera1, TweeningInformation, PartProperties)
Tween:Play()

while wait(0.01) do 
	camera.CFrame = camera1.CFrame 
end

Thank you for the help in advance.

Look into using the Tween object’s Completed event.

Tween.Completed:Connect(function(playbackState)
  print("Tween completed with:",playbackState)
end)
1 Like