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 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.