✓ Accepted answer
This is one way you can do this without having to repeat if statements. You'll need to rename all of your camera parts in the order you want (Cam1, Cam2, Cam3, etc). Basically, it grabs the CurrentCam's fourth string in its name to get the number then adds that number by 1 to find the next camera.
local CurrentCam = nil
local Camera = workspace.CurrentCamera
local CameraParts = workspace.Cams:GetChildren()
local function onClick()
local nextCam, nextCamNum, currentCamNum
if CurrentCam then
currentCamNum = string.sub(CurrentCam.Name, 4, 4)
if currentCamNum then
nextCamNum = tonumber(currentCamNum) + 1
nextCam = CameraParts:FindFirstChild("Cam" .. tostring(nextCamNum))
if nextCam then
CurrentCam = nextCam
Camera.CameraSubject = CurrentCam
else
CurrentCam = CameraParts.Cam1
Camera.CameraSubject = CurrentCam
end
end
else
CurrentCam = CameraParts.Cam1
Camera.CameraSubject = CurrentCam
end
end
script.Parent.MouseButton1Click:Connect(onClick)
2 comments
Your question is confusing. Do you want it to go in order or in a random order?
i want it to go in order.