Howdy, I want to get all the parts Cframes inside a folder, then move the camera Cframes, one by one.
like, the camera changes cframe to one child, five sec after, the next one, and so on until theres no more left and then just go back to the normal camera
the issue is that the loop gets ALL the cframes at once making it move constanly to the side
i have tried to change the kind of loop, move it to the server, and nothing works
this following script is my current attemp, that basically is the same, is activated though a remote event, but it gets all variables itself, is a local script, inside the Gui
local Cameras = workspace:WaitForChild("Cameras")
CameraEvent.OnClientEvent:Connect(function()
Camera.CameraType = Enum.CameraType.Scriptable
local children = Cameras:GetChildren()
for i = 1, #children do
if children[i]:IsA("BasePart") then
print( children[i].Name .. " CFrame:".. children[i].CFrame)
Camera.CFrame = children[i].CFrame
task.wait(5)
children[i]:Destroy()
end
end
Camera.CameraType = Enum.CameraType.Custom
end)
i also tried a inpairs loop, a while loop, and others, if any of you need more information, just ask!, id try my best to reply
As far as I can tell the code does what you say it should do. I don’t understand what you mean by how it’s behaving.
Some things to watch out for.
Having that event fire multiple times while it’s running
Ordering incorrectness by just pulling children.
Another script moving the camera.
Yet, as i said so, it prints and gives all the cframes, not just one
Server:
Client:
i changed the script in another attemp to fix it, now the server is the one giving the cframe to the client, but is basically the same, but at least is not moving weirdly!
Since this seems like it’s only intended to run once, you could simply set up CameraEvent.OnClientEvent to run once and run the code.
Workspace:WaitForChild("Cameras")
local CameraObjects = Workspace.Cameras:GetChildren()
for i = #CameraObjects, 1, -1 do
local cam = CameraObjects[i]
if cam:IsA("BasePart") == false then
table.remove(CameraObjects, i)
end
end
CameraEvent.OnClientEvent:Wait()
Camera.CameraType = Enum.CameraType.Scriptable
for _, cam in ipairs(CameraObjects) do
Camera.CameraSubject = cam
Camera.CFrame = cam.CFrame
wait(5)
cam:Destroy()
end
Camera.CameraSubject = Player.Character.Humanoid
Camera.CameraType = Enum.CameraType.Custom
actually now that i think about it, the print statement IS the problem, you can’t concatenate a CFrame with a string. (And I doubt you’d want to, CFrames are absurdly long. I suggest using position instead.)
Use string interpolation instead, or alternatively convert the CFrame to a string with tostring().
local cameras = workspace:WaitForChild("Cameras")
local camera = workspace.CurrentCamera
local cameraEvent = game.ReplicatedStorage.RemoteEvent
cameraEvent.OnClientEvent:Connect(function()
camera.CameraType = Enum.CameraType.Scriptable
for _, cameraPart in cameras:GetChildren() do
if cameraPart:IsA("BasePart") then
print(`{cameraPart.Name} CFrame: {cameraPart.CFrame}`)
camera.CFrame = cameraPart.CFrame
task.wait(5)
cameraPart:Destroy()
end
end
camera.CameraType = Enum.CameraType.Custom
end)