So I followed a tutorial on how to create a security camera system created by kingerman88, all went well and I had the cameras pulled up and able to start switching cameras. I tried to switch cameras again after the 4th time and an error came up stating "attempt to index nil with 'Name' - Line 26" and nothing happens. I press switch camera again and it works fine until I hit the 4th camera, then the same error.
local remoteEvent = game.ReplicatedStorage:WaitForChild('CameraEvent') local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:Wait() local Camera = workspace.CurrentCamera local LeftArrow = script.Parent.LA -- Create extra definitions for easy use local RightArrow = script.Parent.RA local CameraName = script.Parent.CameraName Camera.CameraType = Enum.CameraType.Scriptable local Cameras = game.Workspace.Cameras:GetChildren() -- this is the table of all the cameras local index = 1 function ChangeCamera() -- This function will be fired when a button is pressed if index < 1 then -- The index is less than 0 so we will put the last camera in the table index = #Cameras + 1 elseif index > (#Cameras + 1) then -- You reached the last camera index = 1 end if index == 0 then -- When the index is 0 set the camera to the player CameraName.Text = "Nil" Camera.CameraType = Enum.CameraType.Scriptable Camera.CameraSubject = Character.Humanoid else CameraName.Text = " "..Cameras[index].Name -- This is the camera part's name Camera.CameraType = Enum.CameraType.Scriptable Camera.CFrame = Cameras[index].CFrame -- The Camera Part's Cframe end end LeftArrow.MouseButton1Click:Connect(function() --Event for when the button is pressed index -= 1 --Changing the index -1 ChangeCamera() --Fire the function end) RightArrow.MouseButton1Click:Connect(function() index += 1 ChangeCamera() end)
Any solutions on what is happening?
Cameraname is nil; it appears it doesn't exist.