Cameras Breaking after Exiting and going back in

local player = game.Players.LocalPlayer.UserId
local characterName = game.Players:GetNameFromUserIdAsync(player)
local char = game.Workspace:WaitForChild(characterName)
local hum = char:WaitForChild("Humanoid")
local	camera = workspace.CurrentCamera
local current = script.current.Value
camera.CameraType = Enum.CameraType.Fixed
local UserInputService = game:GetService("UserInputService")
local actionKey = Enum.KeyCode
function playCam()
	game.Workspace.sounds.CamsChange:Play()
end
camera.CameraSubject = hum
local camsGui = script.Parent.Parent.PlayerGui.ScreenGui.Cams
game.ReplicatedStorage:WaitForChild("camsOn")
camera.CameraSubject = hum
game.Workspace.computer.Part.ClickDetector.MouseClick:Connect(function()
	game.ReplicatedStorage.camsChanged:Fire("showstage")
	script.Parent.Parent.CameraMode = Enum.CameraMode.Classic
	script.Parent.Parent.CameraMinZoomDistance = 5
	game.ReplicatedStorage.camsOn.Value = true	
	
	if current == "parts" then
		camera.CameraSubject = game.Workspace.partsandservice
	elseif current == "vent1" then
		camera.CameraSubject = game.Workspace.VentCam1
	elseif current == "vent2" then
		camera.CameraSubject = game.Workspace.VentCam2
	elseif current == "vent3" then
		camera.CameraSubject = game.Workspace.VentCam3
	elseif current == "vent4" then
		camera.CameraSubject = game.Workspace.VentCam4
	elseif current == "showstage" then
		camera.CameraSubject = game.Workspace.showstage
	end
	
	--game.StarterGui.ScreenGui.CameraGUI.Visible = true
	game.Lighting.FogEnd = 300
	game.Workspace.sounds.CamsChange:Play()
	camera.FieldOfView = 90
	local Players = game:GetService("Players")
 
local localPlayer = Players.LocalPlayer
local mouse = localPlayer:GetMouse()
                                                                     
game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
	
	if inputObject.KeyCode == Enum.KeyCode.S and game.ReplicatedStorage.camsOn.Value == true then --Also, could be written as [[inputObject.KeyCode == "R"]]
     	--local vPlayer = game.Players.LocalPlayer
		--local character = vPlayer.Character
		script.current.Value = "showstage"
		game.ReplicatedStorage.camsChanged:Fire("none")
		game.ReplicatedStorage.camsOn.Value = false
		script.Parent.Parent.CameraMode = Enum.CameraMode.LockFirstPerson
		script.Parent.Parent.CameraMinZoomDistance = 0.5
		--local humanoid = character:FindFirtChild('Humanoid') -- This should detect the humanoid of the player
		game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Follow
		playCam()
		game.Lighting.FogEnd = 50
		--game.StarterGui.ScreenGui.CameraGUI.Visible = false
		--game.StarterGui.ScreenGui.Cameras.Visible = false
		game.Workspace.CurrentCamera.CameraSubject = hum
		game.Workspace.CurrentCamera.FieldOfView = 70
		
    end 
end)

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
	
 	if inputObject.KeyCode == Enum.KeyCode.E and script.current.Value == "parts" and game.ReplicatedStorage.camsOn.Value == true  then --Also, could be written as [[inputObject.KeyCode == "R"]]
     	game.Workspace.CurrentCamera.CameraSubject = game.Workspace.VentCam1
		script.current.Value = "vent1"
		game.ReplicatedStorage.camsChanged:Fire("vent1")
		playCam()
	elseif inputObject.KeyCode == Enum.KeyCode.E and script.current.Value == "vent1"and game.ReplicatedStorage.camsOn.Value == true then
		game.Workspace.CurrentCamera.CameraSubject = game.Workspace.VentCam2
		game.ReplicatedStorage.camsChanged:Fire("vent2")
		script.current.Value = "vent2"
		playCam()
	elseif inputObject.KeyCode == Enum.KeyCode.E and script.current.Value == "vent2" and game.ReplicatedStorage.camsOn.Value == true then
		game.Workspace.CurrentCamera.CameraSubject = game.Workspace.VentCam3
		game.ReplicatedStorage.camsChanged:Fire("vent3")
		script.current.Value = "vent3"
		playCam()
	elseif inputObject.KeyCode == Enum.KeyCode.E and script.current.Value == "vent3" and game.ReplicatedStorage.camsOn.Value == true then
		game.Workspace.CurrentCamera.CameraSubject = game.Workspace.VentCam4
		game.ReplicatedStorage.camsChanged:Fire("vent4")
		script.current.Value = "vent4"
		playCam()
	elseif inputObject.KeyCode == Enum.KeyCode.E and script.current.Value == "vent4" and game.ReplicatedStorage.camsOn.Value == true then
		game.Workspace.CurrentCamera.CameraSubject = game.Workspace.VentCam5
		game.ReplicatedStorage.camsChanged:Fire("vent5")
		script.current.Value = "vent5"
		playCam()
	elseif inputObject.KeyCode == Enum.KeyCode.E and script.current.Value == "vent5"and game.ReplicatedStorage.camsOn.Value == true then
		game.Workspace.CurrentCamera.CameraSubject = game.Workspace.showstage
		game.ReplicatedStorage.camsChanged:Fire("showstage")
		script.current.Value = "showstage"
		playCam()
	elseif inputObject.KeyCode == Enum.KeyCode.Q and script.current.Value == "showstage"and game.ReplicatedStorage.camsOn.Value == true then
		game.Workspace.CurrentCamera.CameraSubject = game.Workspace.VentCam5
		game.ReplicatedStorage.camsChanged:Fire("vent5")
		script.current.Value = "vent5"
		playCam()
	elseif inputObject.KeyCode == Enum.KeyCode.Q and script.current.Value == "vent5" and game.ReplicatedStorage.camsOn.Value == true then
		game.Workspace.CurrentCamera.CameraSubject = game.Workspace.VentCam4
		game.ReplicatedStorage.camsChanged:Fire("vent4")
		script.current.Value = "vent4"
		playCam()
	elseif inputObject.KeyCode == Enum.KeyCode.Q and script.current.Value == "vent1" and game.ReplicatedStorage.camsOn.Value == true then
		game.Workspace.CurrentCamera.CameraSubject = game.Workspace.partsandservice
		game.ReplicatedStorage.camsChanged:Fire("parts")
		script.current.Value = "parts"
		playCam()
	elseif inputObject.KeyCode == Enum.KeyCode.Q and script.current.Value == "vent4" and game.ReplicatedStorage.camsOn.Value == true then
		game.Workspace.CurrentCamera.CameraSubject = game.Workspace.VentCam3
		game.ReplicatedStorage.camsChanged:Fire("vent3")
		script.current.Value = "vent3"
		playCam()
	elseif inputObject.KeyCode == Enum.KeyCode.Q and script.current.Value == "vent3"and game.ReplicatedStorage.camsOn.Value == true then
		game.Workspace.CurrentCamera.CameraSubject = game.Workspace.VentCam2
		game.ReplicatedStorage.camsChanged:Fire("vent2")
		script.current.Value = "vent2"
		playCam()
	elseif inputObject.KeyCode == Enum.KeyCode.Q and script.current.Value == "vent2"and game.ReplicatedStorage.camsOn.Value == true then
		game.Workspace.CurrentCamera.CameraSubject = game.Workspace.VentCam1
		game.ReplicatedStorage.camsChanged:Fire("vent1")
		script.current.Value = "vent1"
		playCam()
    end 
end)
	
	--game.StarterGui.ScreenGui.Cameras.Visible = true
	
end)

So after you read through my absolute hodge-podge of code here, let me explain the problem. When you first play the game, you are able to go through every single camera just fine. Once you press S and click the cameras again, thats when things get to be wierd. The 2nd time you view the cameras, you cant flip to the 1st, 3rd, and 5th cameras respectively. The 3rd time you view the cameras, you can only view 3 of the cameras. This has had me very confused for a while, so any help would be great.

Yeah the code is very repetitive and you are hard coding the vents, are you trying to make like a security camera system?

Yes I am, and I will definitly need to clean up the code once im fix the problem

Hey NotDeveloperKitty, did you test this more than once for it to be exactly the 1st, 3rd and 5th cameras not being able to be view-able?

What I might be trying to understand from this is that when you pressed S, you did the following:
script.current.Value = "showstage" game.ReplicatedStorage.camsChanged:Fire("none")
However you didn’t change the Camera’s subject for it as you’ve done for every other time you’ve used the current object value and the bindable.

Im reading this code and im confused on what you are trying to get this to look like could to send a video of what you are trying to do and maybe i could help thanks.

I Hope this Helps if you have any questions ask

--Im not sure is this is what you are looking for but hope it helps you out 
 --Make a new folder in workspace and name it "AllCams" and put any cams you are going to use in it and make sure to add there name and order you would like in the cam list
local player = game.Players.LocalPlayer.UserId
local characterName = game.Players:GetNameFromUserIdAsync(player)
local char = game.Workspace:WaitForChild(characterName)
local hum = char:WaitForChild("Humanoid")
local camera = workspace.CurrentCamera
local current = script.current.Value -- CHANGE TO A NUMBER VALUE

local CamList = {
	{Name = "VentCam1"};--1
	{Name = "VentCam2"};--2
	{Name = "VentCam3"};--3
	{Name = "VentCam4"};--4
	{Name = "VentCam5"};--5
	{Name = "showstage"};--6
	{Name = "partsandservice"};--7
}

local UserInputService = game:GetService("UserInputService")
local actionKey = Enum.KeyCode
function playCam()
	game.Workspace.sounds.CamsChange:Play()
end
camera.CameraSubject = hum
game.Workspace.computer.Part.ClickDetector.MouseClick:Connect(function()
	game.ReplicatedStorage.camsChanged:Fire("showstage")
	script.Parent.Parent.CameraMode = Enum.CameraMode.Classic
	script.Parent.Parent.CameraMinZoomDistance = 5
	game.ReplicatedStorage.camsOn.Value = true	
	game.Lighting.FogEnd = 300
	game.Workspace.sounds.CamsChange:Play()
	camera.FieldOfView = 90
	local Players = game:GetService("Players")
	local localPlayer = Players.LocalPlayer
	local mouse = localPlayer:GetMouse()
	game.Workspace.CurrentCamera.CameraSubject = game.Workspace.AllCams:FindFirstChild(CamList[script.current.Value].Name)
end)                                                                   
game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
	
	if inputObject.KeyCode == Enum.KeyCode.S and game.ReplicatedStorage.camsOn.Value == true then 
		game.ReplicatedStorage.camsChanged:Fire("none")
		game.ReplicatedStorage.camsOn.Value = false
		script.Parent.Parent.CameraMode = Enum.CameraMode.LockFirstPerson
		script.Parent.Parent.CameraMinZoomDistance = 0.5
		game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Follow
		playCam()
		game.Lighting.FogEnd = 50
		game.Workspace.CurrentCamera.CameraSubject = hum
		game.Workspace.CurrentCamera.FieldOfView = 70
		
	end 
	
	if inputObject.KeyCode == Enum.KeyCode.E and game.ReplicatedStorage.camsOn.Value == true then
		if script.current.Value == #CamList then
			script.current.Value = 1
		else
			script.current.Value = script.current.Value + 1
		end
     	game.Workspace.CurrentCamera.CameraSubject = game.Workspace.AllCams:FindFirstChild(CamList[script.current.Value].Name)
		game.ReplicatedStorage.camsChanged:Fire(CamList[script.current.Value].Name)
		playCam()
	end
	if inputObject.KeyCode == Enum.KeyCode.Q and game.ReplicatedStorage.camsOn.Value == true then
		if script.current.Value == 1 then
			script.current.Value = #CamList
		else
			script.current.Value = script.current.Value - 1
		end
     	game.Workspace.CurrentCamera.CameraSubject = game.Workspace.AllCams:FindFirstChild(CamList[script.current.Value].Name)
		game.ReplicatedStorage.camsChanged:Fire(CamList[script.current.Value].Name)
		playCam()
	end
    end)
2 Likes