I got this code that uses a folder of CFrameValues to change the CFrame of a player’s camera.
The problem is when I need to loop through the folder, is there a way to use RunService instead of a for loop since RunService is a loop?
local folder = game.Workspace:WaitForChild("CutScenes"):WaitForChild("Camera1"):WaitForChild("Frames"):GetChildren()
local frames = #folder
local camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
game:GetService("RunService").RenderStepped:Connect(function()
for i=1,frames do
camera.CameraType = Enum.CameraType.Scriptable
local cf = folder[i]
camera.CFrame = cf.Value
end
end)
Use a run service while loop to change the cframe to the index
local folder = game.Workspace:WaitForChild("CutScenes"):WaitForChild("Camera1"):WaitForChild("Frames"):GetChildren()
local frames = #folder
local camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
camera.CameraType = Enum.CameraType.Scriptable
local index = 0
local cf = nil
while game:GetService("RunService").RenderStepped:Wait() do
index = index + 1
if folder[index] == nil then break end
cf = folder[index]
camera.CFrame = cf.Value
end
Youll need to instead define a new array, The sort it according to your order, Which you can use table.sort, And also I suggest using beizier curve or something, idk as the script executes every 16 mili second and thus TP very fast
No I mean sorta like and you gotta also name them in order, Alphabet would be best
local folder = game.Workspace:WaitForChild("CutScenes"):WaitForChild("Camera1"):WaitForChild("Frames"):GetChildren()
folder = table.sort(folder, function(a,b)
return a.Name< b.Name
end)
local camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
camera.CameraType = Enum.CameraType.Scriptable
local index = 0
local cf = nil
while game:GetService("RunService").RenderStepped:Wait() do
index = index + 1
if folder[index] == nil then break end
cf = folder[index]
camera.CFrame = cf.Value
end