local function animateCamera(rootPart, camera, cameraScenes)
local initialCameraFrame = rootPart.CFrame:ToObjectSpace(camera.CFrame)
local initialCameraType = camera.CameraType
camera.CameraType = Enum.CameraType.Scriptable
for _, cameraScene in pairs(cameraScenes) do
camera.CFrame = rootPart.CFrame:ToWorldSpace(cameraScene.InitialOffset)
local cameraTween = TweenService:Create(camera, cameraScene.TweenInfo, {CFrame = rootPart.CFrame:ToWorldSpace(cameraScene.EndOffset)})
cameraTween:Play()
cameraTween.Completed:Wait()
cameraTween:Destroy()
task.wait(cameraScene.Delay)
end
camera.CFrame = rootPart.CFrame:ToWorldSpace(initialCameraFrame)
camera.CameraType = initialCameraType
end
animateCamera(rootPart, camera, cameraScenes)
and this is my script
local TweenService = game:GetService("TweenService")
local rootPart = script.Parent.PrimaryPart
local camera = workspace.CurrentCamera
local cameraScenes = {
{
InitialOffset = CFrame.new(-1.84375, 2.28120041, -3.72264099, -0.896119118, 0.246898666, -0.368797451, 0, 0.830973744, 0.556311667, 0.443813562, 0.498521507, -0.744651496),
EndOffset = CFrame.new(3.859375, 2.22237015, -5.30947876, -0.833500385, -0.188059226, 0.519529402, -1.49011594e-08, 0.940292656, 0.340367049, -0.552518845, 0.283696055, -0.783734381),
TweenInfo = TweenInfo.new(),
Delay = 1
},
{
InitialOffset = CFrame.new(0.22265625, 2.32366562, -3.40678406, -0.999632716, -0.0136118429, 0.0234374292, 0, 0.864740789, 0.502218664, -0.0271034185, 0.502034187, -0.864423096),
EndOffset = CFrame.new(0.21875, 3.28287125, -5.10414124, -0.999838889, 0.0088400282, -0.0156248957, 0, 0.870358527, 0.492418826, 0.017952254, 0.492339492, -0.870218217),
TweenInfo = TweenInfo.new(6, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut),
Delay = 5
},
{
InitialOffset = CFrame.new(2.56640625, 1.81679153, 1.74195862, 0.913751185, 0.00280294032, 0.406264722, -2.32830644e-10, 0.999976337, -0.00689913006, -0.406274408, 0.00630408805, 0.913729429),
EndOffset = CFrame.new(1.765625, 1.5592804, 1.74745178, 0.919699013, 0.0395444073, 0.390627652, 0, 0.994915009, -0.10071823, -0.39262411, 0.0926304534, 0.915022373),
TweenInfo = TweenInfo.new(5, Enum.EasingStyle.Quart, Enum.EasingDirection.InOut),
Delay = 1
}
}
local function animateCamera(rootPart, camera, cameraScenes)
local initialCameraFrame = rootPart.CFrame:ToObjectSpace(camera.CFrame)
local initialCameraType = camera.CameraType
camera.CameraType = Enum.CameraType.Scriptable
for _, cameraScene in pairs(cameraScenes) do
camera.CFrame = rootPart.CFrame:ToWorldSpace(cameraScene.InitialOffset)
local cameraTween = TweenService:Create(camera, cameraScene.TweenInfo, {CFrame = rootPart.CFrame:ToWorldSpace(cameraScene.EndOffset)})
cameraTween:Play()
cameraTween.Completed:Wait()
cameraTween:Destroy()
task.wait(cameraScene.Delay)
end
camera.CFrame = rootPart.CFrame:ToWorldSpace(initialCameraFrame)
camera.CameraType = initialCameraType
end
animateCamera(rootPart, camera, cameraScenes)