for i = 1, #FolderDirectory:GetChildren() do --> Change FolderDirectory to where your cameras are stored.
print(i) --> We can print i which is the number of items in your FolderDirectory.
--> The print should return the amount of Instances inside the folder.
end
are you trying to loop through the instances in the folder? or are you trying to get the instances in the folder in a numbered sequence like 1, 2, 3, 4…?
thats what my script does.
you can name the instances in a numbered manner.
for example, name them 1, then 2, then 3 etc.
local FolderWithInstances= -- the folder which has the instances in numbered manner
for i=1, #FolderWithInstances:GetChildren() do
local FolderNumber=i -- this is your folder number
local Object=FolderWithInstances:FindFirstChild(FolderNumber)
-- this object is your instances in the numbered order"
end
for i,v in pairs(FolderDirectory :GetChildren()) do --> Gets the children of FolderDirectory.
print(i,v) --> Prints the index, and value of the children in the FolderDirectory.
end
You’re going to have to order the camera parts manually. If you want to cycle, you can do something like this:
--!strict
local CameraParts: {BasePart} = {
[1] = workspace.Camera1,
[2] = workspace.Camera2,
[3] = workspace.Camera3
}
local currentCameraPart: BasePart? = nil
local function cycle(direction: "next" | "previous"): BasePart
local currentCameraPartIndex: number? = table.find(CameraParts, currentCameraPart :: BasePart)
if currentCameraPartIndex ~= nil then
if (direction == "next" and currentCameraPartIndex == #CameraParts) or (direction == "previous" and currentCameraPartIndex == 1) then
return CameraParts[if direction == "next" then 1 else #CameraParts]
else
return CameraParts[currentCameraPartIndex + (if direction == "next" then 1 else -1)]
end
else
return CameraParts[1]
end
end
-- example cycle
local previousButton = script.Parent.Previous
local nextButton = script.Parent.Next
previousButton.Activated:Connect(function(): ()
currentCameraPart = cycle("previous")
-- do camera stuff
end)
nextButton.Activated:Connect(function(): ()
currentCameraPart = cycle("next")
-- do camera stuff
end)