Cutscene stopping at the wrong time

I have a cutscene that flows through the map. The camera works just fine, but when it reaches part 7 out of 14 it stops. The script is fine but I don’t know why it just stops like that. Here is my script:

``local TweenServive = game:GetService(“TweenService”)

local camera = game.Workspace.Camera

local cutsceneTime = 5

local tweenInfo = TweenInfo.new(
cutsceneTime,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
false,
0
)

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

local tween = TweenServive:Create(camera, tweenInfo, {CFrame = part2.CFrame})
tween:Play()

wait(cutsceneTime)

camera.CameraType = Enum.CameraType.Custom

end

wait(0)

tween(game.Workspace.Test1,game.Workspace.Test2)
tween(game.Workspace.Test2,game.Workspace.Test3)
tween(game.Workspace.Test3,game.Workspace.Test4)
tween(game.Workspace.Test4,game.Workspace.Test5)
tween(game.Workspace.Test5,game.Workspace.Test6)
tween(game.Workspace.Test6,game.Workspace.Test7)
tween(game.Workspace.Test7,game.Workspace.Test8)
tween(game.Workspace.Test8,game.Workspace.Test9)
tween(game.Workspace.Test9,game.Workspace.Test10)
tween(game.Workspace.Test10,game.Workspace.Test11)
tween(game.Workspace.Test11,game.Workspace.Test12)
tween(game.Workspace.Test12,game.Workspace.Test13)
tween(game.Workspace.Test13,game.Workspace.Test14)``

1 Like

Is part 7 anchored? is it labeled correctly? also check the same for part 8.

1 Like

They are all anchored and they are all spelt right.

image


this is the entire script

You have a space after the Test7, delete this space and you are good to go.

1 Like

I have other posts on my cutscene, are you able to help with them? Click play to end cutscene and spawn in
How do I make gui fit all platforms/screens? - #2 by Ty_Scripts

I use a cutscene plugin, makes this a lot easier:

Try Codes Otaku Cutscene plugin… has a link to a YT video that explains how to use it.

2 Likes
local TweenService = game:GetService("TweenService")

local camera = game.Workspace.CurrentCamera

local cutsceneTime = 5

local tweenInfo = TweenInfo.new(
	cutsceneTime,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

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

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

	tween.Completed:Wait()

	camera.CameraType = Enum.CameraType.Custom
end

task.wait()

local ObjectsToTween = {}
function addTweenObject(index, obj)
	ObjectsToTween[index] = obj
end

local TweenObjectsLocation = game.Workspace -- I suggest adding them to a folder and then changing the variable to their parent

local Prefix = "Test" -- name of part before it's cutscene number

for i,v in pairs(TweenObjectsLocation:GetChildren()) do
	if v.Name:lower():find(Prefix) then
		if #v.Name > #(Prefix) then
			local number = v.Name:sub(#(Prefix) + 1, #v.Name)
			if tonumber(number) ~= nil then
				addTweenObject(tonumber(number), v)
			end
		end
	end
end

for i,v in pairs(ObjectsToTween) do
	if i < #ObjectsToTween then
		tween(v, ObjectsToTween[i + 1])
	end
end

Remember that to access the client’s camera, you have to use the CurrentCamera object and not the workspace camera. I also optimized your script to go through all the cutscenes without needing multiple lines. Just make sure to put this in a LocalScript, because I think camera is client-based… Either put it in StarterPlayerScripts or StarterCharacterScripts.

1 Like

Hi!

I would suggest that you use

tween.Completed:Wait()

over

wait(cutsceneTime)

This makes sure that the tween actually finishes, before proceeding. :slight_smile:

Edit: also use task.wait() instead of wait() for all future projects.

1 Like