Introduction
Hello there,
I’m currently trying to make a flying camera intro, basically a Part that is flying around the map to various destinations. To make this, I put the player camera in a Camera Part, that I’m tweening around the map to other parts to create the scene.
The Problem
I got all the Parts in a Folder in the Workspace, numbered from 1-8 in this case. I then tried to tween the CameraPart to each part via for loop. A friend told me, that for loops always “run” through the Explorer in it’s listed sequence, so I numbered the parts from 1-8 as I said above. My problem is, that the CameraPart still tweens to random parts in the table of parts it should tween to, and not in the sequence I numbered them.
My Explorer:
The CameraPart should Tween to the position and orientation of each Part in the FlyToParts Folder.
My Code, LocalScript in StarterPlayerScripts:
local RS = game:GetService("RunService")
local TS = game:GetService("TweenService")
local CameraPart = workspace.CameraSystem.CameraPart
local FlyToParts = workspace.CameraSystem.FlyToParts
local Camera = workspace.Camera
local SceneRunning = false
local Tween = nil
local Goal = nil
local TweenTime = 2
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CameraSubject = CameraPart
Camera.CFrame = CameraPart.CFrame
local TI = TweenInfo.new(TweenTime,Enum.EasingStyle.Linear)
RS.RenderStepped:Connect(function()
if SceneRunning then
Camera.CFrame = CameraPart.CFrame
end
end)
function FlyScene()
SceneRunning = true
for _, FlyToPart in pairs(FlyToParts:GetChildren())do
Goal = {}
Goal.Position = FlyToPart.Position
Goal.Orientation = FlyToPart.Orientation
Tween = TS:Create(CameraPart,TI,Goal)
Tween:Play()
wait(TweenTime)
end
print("Flight ended")
end
FlyScene()
The Result
robloxapp-20210605-1453112.wmv (2.0 MB) Sorry for the lag, I don’t have that good of a PC.
Also, no errors in the Output.
I’m not the best of a scripter, but I hope you can help me with my issue. Any help is appreciated!