Attempt to Index nil with 'CFrame'

Hello, I was trying to make a character customizer and I was starting with the camera but isn’t working. Could anyone help me?

All the code:

Error line:


Thanks.

I don’t think you need to use WaitForChild:() if the object is in the explorer already, the same goes for remotes.

I think CameraType needs to be an Enum.CameraType for one, for two, camPart must not exist, hence why you’re indexing nil.

Try this, and tell me the print outputs if it doesn’t work:


-- Services
local WS = game:GetService("Workspace")
local RS = game:GetService("ReplicatedStorage")

-- Objects/Variables
local cam = WS.CurrentCamera

local camPart = WS:WaitForChild("CamPart", 2)
if not camPart then
    error("camPart does not exist!")
end

local remote = RS:WaitForChild("CE", 2)
if not remote then
    error("CE does not exist!")
end

-- Remote Event Definitions
remote.OnClientEvent:Connect(function(what, arg1, arg2)

    -- Just print these for debugging, remove this pcall if things work.
    pcall(function()
        print(what)
        print(arg1)
        print(arg2)
    end)

    if what == "ApplyCECam" then
        cam.CameraType = Enum.CameraType.Scriptable
        cam.CFrame = camPart.CFrame
    end
end)

Thank you, it solved the script.

1 Like

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