Menu Cameras wont stop looping tween. Help!

Im making a menu for my game, though the menu envolves camera that tween between one another. Though when the ‘Play’ button is clicked by the player the player’s camera doesn’t stop looping like it should and return to the player, instead it starts looping the camera between the camera parts and the player repeatedly. if anyone knows the way round this i’d highly appriciate some help.

– Services
local TweenService = game:GetService(“TweenService”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local Players = game:GetService(“Players”)
local Workspace = game:GetService(“Workspace”)

– Objects
local Camera = Workspace.CurrentCamera
local CameraPointsFolder = Workspace:WaitForChild(“CameraPoints”) – Folder where all camera points are stored
local GUIFunctions = require(script.Parent.GUIFunctions) – Assuming GUIFunctions is in the same folder

– Event for the Play Button
local MainMenuEvent = ReplicatedStorage:WaitForChild(“MainMenuEvent”)

– Get all camera points and sort them by name
local CameraPoints = CameraPointsFolder:GetChildren()
table.sort(CameraPoints, function(a, b)
return tonumber(a.Name) < tonumber(b.Name) – Ensures cameras are sorted in correct order
end)

– Variable to track if the play button has been clicked
local playClicked = false
local currentTween – Store the current tween to cancel it if needed

– Function to transition camera between points (tweening)
local function TweenBetweenCameras(startPoint, endPoint, duration)
if playClicked then return end – Stop immediately if play is clicked

local startPosition = startPoint.Position
local endPosition = endPoint.Position

-- Tween the Camera's CFrame position while keeping the camera's current orientation intact
currentTween = TweenService:Create(Camera, TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {
    CFrame = CFrame.new(endPosition) -- Moves the camera to the next position
})

currentTween:Play()
currentTween.Completed:Wait() -- Wait for the tween to finish

-- Stop the tween early if playClicked is true
if playClicked then
    currentTween:Cancel()
end

end

– Function to teleport the camera instantly to a point (no tweening)
local function TeleportCamera(point)
Camera.CFrame = CFrame.new(point.Position) – Instantly teleport to the point
end

– Main function to handle the camera transitions
task.spawn(function()
– Wait until the menu is visible
repeat task.wait() until GUIFunctions.MenuFrame.Visible

-- Control the camera after the menu is visible
GUIFunctions:ControlCamera(true)

-- Set camera instantly to Camera 1 on load
TeleportCamera(CameraPoints[1])

-- Loop through camera points and perform transitions continuously
while not playClicked do
    for i = 1, #CameraPoints - 1 do
        if playClicked then break end -- Exit loop immediately

        local currentPoint = CameraPoints[i]
        local nextPoint = CameraPoints[i + 1]

        -- Tween between cameras
        TweenBetweenCameras(currentPoint, nextPoint, 4) -- 4 seconds to tween

        -- If we reach the last camera, teleport back to the first
        if i == #CameraPoints - 1 then
            TeleportCamera(CameraPoints[1]) -- Teleport to the first camera instantly
        end
    end
end

end)

– Event to stop the camera cycling when Play button is clicked
MainMenuEvent.OnServerEvent:Connect(function(Player, Action)
if Action == “Play” then
– Set playClicked to true to stop camera cycling
playClicked = true

    -- Cancel any ongoing tween
    if currentTween then
        currentTween:Cancel()
    end

    -- Stop camera cycling and allow player to control the camera
    GUIFunctions:ControlCamera(false)

    -- Instantaneously move the camera back to the player
    local playerCharacter = Players.LocalPlayer.Character
    if playerCharacter and playerCharacter:FindFirstChild("HumanoidRootPart") then
        Camera.CFrame = CFrame.new(playerCharacter.HumanoidRootPart.Position)
    end
end

end)