Hello!
I’m currently trying to tween a cutscene that has multiple camera points in a map with the use of TweenService. It works sometimes, but here’s the problem:
When I test out the cutscene the first time, the camera only focuses on one camera point and not the rest of the camera points. After waiting a while, the cutscene script (which is a local script btw) finds the camera points in the map and runs normally.
Here’s what I did/scripted up until this point:
-
When players (split into 2 teams (runners and the killer)) are teleported inside a randomly selected map, the server fires a RemoteEvent through :FireClients() / :FireClient(), and it enables the map cutscene.
-
In the Client-Side of the game, the Cutscene script finds the camera points in the map (in Workspace, labeled “Point1”, “Point2”, etc) and adds them into a number/variable?? (idk the terminology, let’s just call it CameraList) so the camera can cycle through the points. All of this is inside a function and returns the CameraList so it can be used later on.
-
The cutscene script then grabs the CameraList from the previous function; sets the camera to “Scriptable” and to the first CameraPoint in the map, and cycles through all of the camera points in a for loop. I also threw in a pcall inside the for loop for debugging purposes (just in case if something goes wrong).
Here’s what I’ve attempted to solve the problem:
- I’ve tried looking for existing points inside CameraParts (see “hierarchy of the CameraPoints” below) in a generic for ipairs loop using string.sub, string.match, etc…
but the output keeps warning me this message (see “the output” below) .
Essentials
the output:
this doesn’t print out any errors, just a warning from the pcall function i did
hierarchy of the CameraPoints:
cutscene script:
--Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
--RemoteEvents
local Network = ReplicatedStorage:WaitForChild("Network")
local RemoteEvents = Network:WaitForChild("RemoteEvents")
local MapCutscene = RemoteEvents:WaitForChild("MapCutscene")
--Variables
local tween
local CutsceneDuration = 8
local Camera = game:GetService("Workspace").CurrentCamera
local CurrentMap = game:GetService("Workspace").MapHandler:WaitForChild("CurrentMap", 500)
local CameraPoints = CurrentMap.Assets:WaitForChild("CameraParts")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
--Functions
local function getCutscenePoints()
local i = 0
for x,y in ipairs(CameraPoints:GetChildren()) do
if string.match(y.Name, "%d+") ~= nil then --If all of the points that start with "Point" followed by a number in numerical order aren't nil then
i = i + 1
end
end
return i
end
--Events
MapCutscene.OnClientEvent:Connect(function(Mode)
if type(Mode) == 'string' then
if Mode == "Activate" then
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CameraPoints:WaitForChild("Point1").CFrame
local get = getCutscenePoints()
print(get)
for i = 1, get do
print('a')
local success, err = pcall(function()
print('running')
local inf = TweenInfo.new(CutsceneDuration, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local goal = {CFrame = CameraPoints["Point"..i + 1].CFrame}
tween = TweenService:Create(Camera, inf, goal)
tween:Play()
wait(CutsceneDuration)
tween:Cancel()
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = Character.Humanoid
end)
if not success then
warn(err)
end
end
end
end
end)
Thanks in advance.