Hello. I can’t solve problem - Players.ars899.PlayerGui.ScreenGui.CameraHandler:27: attempt to index nil with ‘CFrame’.
My workspace: https://i.imgur.com/FS4Vffh.png
StarterGUI - https://i.imgur.com/vGphtWV.png
My code (27: cam.CFrame = camParts[1].CFrame):
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local cam = workspace.CurrentCamera
local function abc(ins)
local children = ins:GetChildren()
table.sort(children,function(c1,c2)
return c1.Name:lower() < c2.Name:lower()
end)
return children
end
local camParts = abc(workspace.Cameras)
local lArrow = script.Parent.LeftArrow
local rArrow = script.Parent.RightArrow
local arrowClickCooldown = false
char:WaitForChild("Humanoid").Seated:connect(function(isS,seat)
if not isS or seat.name~="CamSeat" 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)