Help with security camera system

Hi devs,

i’m currently working on a security camera system but my script gives a error. Can you guys pls give it a watch?

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local cam = workspace.CurrentCamera

local function alphabeticalOrder(instance)
	
	local children = instance:GetChildren()
	
	table.sort(children, function(c1, c2)
		return c1.Name:Lower() < c2.Name:Lower()
	end)
	
	return children
	
end

local camParts = alphabeticalOrder(workspace.Camera)
local LArrow = script.Parent.LeftArrow
local RArrow = script.Parent.RightArrow
local arrowClickCooldown = false

char:WaitForChild("Humanoid").Seated:Connect(function(isSeated, seat)
	
	if not isSeated or seat.Name ~= "CameraSeat" then
		
		script.Parent.LeftArrow.Visible = false
		script.Parent.RightArrow.Visible = false
		
		cam.CameraType = Enum.CameraType.Custom
		return
			
	end
	
	script.Parent.LeftArrow.Visible = true
	script.Parent.RightArrow.Visible = true
	
	cam.CameraType = Enum.CameraType.Scriptable
	cam.CFrame = camParts[1].CFrame
	
	local camNumber = 1
	
	RArrow.MouseButton1Click:Connect(function()
		
		if arrowClickCooldown then
			return
		end
		
		arrowClickCooldown = true
		
		if camNumber == #camParts then
			cam.CFrame = camParts[1].CFrame
			camNumber = 1
		else
			cam.CFrame = camParts[camNumber + 1].CFrame
			camNumber += 1
		end
		
		wait(0.1)
		
		arrowClickCooldown = false
	end)
	
	LArrow.MouseButton1Click:Connect(function()
		if arrowClickCooldown then
			return
		end
		
		arrowClickCooldown = true
		
		if camNumber == 1 then
			
			cam.CFrame = camParts[#camParts].CFrame
			camNumber = #camParts
			
		else
			
			cam.CFrame = camParts[camNumber - 1].CFrame
			camNumber -= 1
		end
		
		wait(0.1)
		
		arrowClickCooldown = false
		
	end)
	
end)

i dont know whats wrong. Pls Help! Thanks for reading!

What’s the error man? Trauma

1 Like

My error is this :

I’m not sure about your code bit confused but I guess. That is where workspace is “alphabeticalOrder” part point to camera, am I right?

I think that the problem here is that the value that you’re trying to call from the table, which in this case is the first index, is nil.

While reading your code, I found out that the camParts table receives its values from the alphabeticalOrder function. In the alphabeticalOrder function, you return the names of the children of the parameter that was passed. When I put this function and a folder with instances into my Roblox Studio to test this out, it gave me an error.

Workspace.Script:6: attempt to call missing method ‘Lower’ of string

I think that you need to fix the alphabeticalOrder function, something is definitely wrong with it. That function may be the source of the problem.

1 Like