Security Camera Looping Issue?

I’m honestly so confused… It should work, it kinda does… But…

I wont include the entire script because there are 18 Cameras but basically I am scripting security cameras that takes the current camera and when you press the Right Arrow it’ll cycle through cameras.

1,2,3 etc etc. However when you first activate the script it by default forces you into Camera one. I can then cycle through 1,2,3 normally. When I get to Camera 18 and then try to loop back to 1, the output tells me I was at 1 but immediately places me on Camera 2. I don’t know why it won’t work because when you look at the script it should… I tried to remove the forcing to camera 1 on start but then that just breaks the script. I will add the script showing what i mean…

| Script |

game.ReplicatedStorage.SecurityCameraEvent.OnClientEvent:Connect(function()
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = Cam1.CFrame
	print(""..player.Name.." is on Cam 1")
	
	
	-- Copy from 21 to 29 -- for more cams -- (just a note for me lol)
HERE--	UIS.InputBegan:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode.Right then
				if Camera.CFrame == Cam1.CFrame then
					Camera.CFrame = Cam2.CFrame
					print(""..player.Name.." is on Cam 2")
				end
			end
		end		
	end)
	------------------------------------------
	
	UIS.InputBegan:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode.Right then
				if Camera.CFrame == Cam2.CFrame then
					Camera.CFrame = Cam3.CFrame
					print(""..player.Name.." is on Cam 3")
				end
			end
		end		
	end)
------------ ALL OTHER CAMERAS --------------
	UIS.InputBegan:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode.Right then
				if Camera.CFrame == Cam18.CFrame then
					Camera.CFrame = Cam1.CFrame
					print(""..player.Name.." is on Cam 1")
				end
			end
		end		
	end)
To Here.

For some reason it skips Camera 1 and goes straight to Camera 2

If i need to explain more i can…

You should consider keeping the camera number separately instead of comparing CFrames, which could go wrong in subtle ways and is less clear. Put your cameras in a list and select them like this:

cameras = { ... }
cameraNumber = 1

local function NextCamera(currentCamera)
	if currentCamera == #cameras then
		return 1
	end

	return currentCamera + 1
end

--Switch Camera CFrame to next Camera
cameraNumber = NextCamera(cameraNumber)
Camera.CFrame = cameras[cameraNumber].CFrame

1 Like

HEY! Im so dang sorry for leaving you on leave for a week! I really didn’t mean that! Im so sorry! I just got busy with something personal. I looked into your method and did some playing around and it works. I changed the initial method into a camera number value and instead of the if statement reading 100 lines of code per click, its now checking a number value.

like

while wait(2) do
     if CamNumber.Value == 1 then
          Camera.CFrame = Cam1.CFrame
     end
     if CamNumber.Value == 2 then
          Camera.CFrame = Cam2.CFrame
     end
end

If i make sense. and moral of my post, you helped solve the issue. :smiley: AGAIN thank you so much for helping and I’m so sorry for ghosting! :smiley: I really appreciate your help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.