Camera Problems

When I press the skip button I want the tweening to stop and the camera to be set back to custom. So I want everything to be normal again but unfortunately this is not the case because when I click the skip button the camera is still tweening and carrying on. my script just completely ignores and pretends like the skip button wasnt even clicked and that there is no code to be executed when its clicked and just keeps moving the cameras cframe in my while loop anyway

local TweenService = game:GetService("TweenService")

local CutsceneFolder = game.Workspace:WaitForChild("CutsceneFolder")

local camera = game.Workspace.Camera

local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")

local TextDisplayGui = PlayerGui:WaitForChild("TextDisplay")
local PlayButton = TextDisplayGui:WaitForChild("Play")
local SkipButton = TextDisplayGui:WaitForChild("Skip")

local currentTween

function tween(part1, part2, tweenInfo)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = part1.CFrame

	currentTween = TweenService:Create(camera, tweenInfo, {CFrame = part2.CFrame})
	currentTween:Play()

	currentTween.Completed:Wait()

	camera.CameraType = Enum.CameraType.Custom
end

PlayButton.MouseButton1Click:Connect(function()
	camera.CameraType = Enum.CameraType.Custom
	if currentTween then
		currentTween:Cancel()
		currentTween = nil
	end
end)

SkipButton.MouseButton1Click:Connect(function()
	camera.CameraType = Enum.CameraType.Custom
	if currentTween then
		currentTween:Cancel()
		currentTween = nil
	end
end)

local cutsceneTime = 10 -- How long the cutscene lasts
local tweenInfo = TweenInfo.new(
	cutsceneTime,
	Enum.EasingStyle.Quad,  -- How it will animate
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

while CutsceneFolder do
	tween(CutsceneFolder["1"], CutsceneFolder["2"], tweenInfo)
	tween(CutsceneFolder["3"], CutsceneFolder["4"], tweenInfo)
	tween(CutsceneFolder["5"], CutsceneFolder["6"], tweenInfo)
end

You didn’t break out of the loop so it just continue redoing the tween

1 Like

OH LMAO I forgot thank you so much

unfortunately that did not work either

Can I see the updated code? Also make sure to check if the completed event actually fired with print

Currently, the event listener for the SkipButton cancels the current tween and sets the camera back to custom, but this code is only executed when the button is clicked, not continuously throughout the while loop.

You could try implementing a variable that is checked in the while loop to determine whether the cutscene should continue playing or not. With this implementation you could set the variable to false when the button is clicked meaning the cutscene won’t continue playing.

Here’s a example

local continueCutscene

while continueCutscene and CutsceneFolder do
    tween(CutsceneFolder["1"], CutsceneFolder["2"], tweenInfo)
    tween(CutsceneFolder["3"], CutsceneFolder["4"], tweenInfo)
    tween(CutsceneFolder["5"], CutsceneFolder["6"], tweenInfo)
end

Make sure to set the continueCutscene variable to false and place it inside the SkipButton function, let me know if this works! :slight_smile: