Trying to break loop when play button is clicked

so i have a looping cutscene for my entrance screen, when the player clicks play i want the cutscene to stop and return to the default player camera type. i appreciate any help ty!

these are my scripts:

local function clickPlay()
	interfaceUI.Enabled = false
	bindable:Fire(true)
end

playButton.MouseButton1Click:Connect(clickPlay)
remote.OnClientEvent:Connect(function()
	local p = game.Players.LocalPlayer
	local c = p.Character
	local ts = game:GetService("TweenService")
	local cam = workspace.CurrentCamera
	local tween = nil
	local WAIT_TIME = 0.05
	local bindable = game.ReplicatedStorage:WaitForChild("stopCutscene")
	local pressedPlay = false
	local cutsceneModel = workspace:WaitForChild("cutsceneModel")

	local cutScenePartsTable = {}

	if cutsceneModel then
		for _, part in ipairs(cutsceneModel:GetChildren()) do
			if part:IsA("Part") or part:IsA("BasePart") or part:IsA("MeshPart") then
				cutScenePartsTable[part.Name] = part
			end
		end
	end

	print(cutScenePartsTable)


	local function createTweens()
		local tweenInfo = TweenInfo.new(20, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)
		cam.CameraType = Enum.CameraType.Scriptable

		cam.CFrame = cutsceneModel:WaitForChild("cameraPoint_yellow").CFrame
		task.wait(WAIT_TIME)
		tween = ts:Create(cam, tweenInfo, {CFrame = cutScenePartsTable.cameraPoint_yellow1.CFrame})
		tween:Play()
		tween.Completed:Wait()

		cam.CFrame = cutScenePartsTable.cameraPoint_pink.CFrame
		task.wait(WAIT_TIME)
		tween = ts:Create(cam, tweenInfo, {CFrame = cutScenePartsTable.cameraPoint_pink1.CFrame})
		tween:Play()
		tween.Completed:Wait()

		cam.CFrame = cutScenePartsTable.cameraPoint_blue.CFrame
		task.wait(WAIT_TIME)
		tween = ts:Create(cam, tweenInfo, {CFrame = cutScenePartsTable.cameraPoint_blue1.CFrame})
		tween:Play()
		tween.Completed:Wait()

		cam.CFrame = cutScenePartsTable.cameraPoint_green.CFrame
		task.wait(WAIT_TIME)
		tween = ts:Create(cam, tweenInfo, {CFrame = cutScenePartsTable.cameraPoint_green1.CFrame})
		tween:Play()
		tween.Completed:Wait()
		task.wait(WAIT_TIME)

	end
	
	bindable.Event:Connect(function(bool)
		pressedPlay = bool
		cam.CameraType = Enum.CameraType.Custom
	end)

	repeat
		createTweens()
	until pressedPlay

end)
5 Likes

im not super well knowledgable about scripting, but may i ask why you use ipairs, instead of just using in pairs, i think it would work the same

2 Likes

hey man, you’re absolutely right for my scenario, my table printed the same.

i used ipairs because my table wasnt in alphabetical order before so when i used pairs, my keys were all over the place so i changed it to ipairs. it works fine now tho. but yes u are right. they do serve different purposes depending on what u use em for tho

2 Likes

ah ok nice to know i helped :+1:

2 Likes