CFrame not working

I have a function that change the cameras CFrame

function Cam.CameraAttach(camera, attachPart)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = camera.CFrame:Lerp(attachPart.CFrame, 0.2)
end

it keeps giving me the output attempt to index nil with 'CFrame’, I dont know if I did it right but based on what i’ve searched and a script I have its correct

the camera is the workspace cam and attach part is where it should go to
also, this code is in a module script since I will be needing it on multiple scripts

Can you send a SS of the entire script and how your using the function cause it’s kind of hard to help you going off of 4 lines of code.

1 Like

Either the camera or attachPart is probably nil. Print out those two things at the top of the function and see what it gives you


(dont mind the player, it still doesnt work even when removing it)
image

aCam is where it should go

oh, it only gives the Camera but not the part that it should attach to
image

image

Where is this script? If partA is nil you probably want to check if its actually there and that workspace.Zone1.Cam is a part in workspace, otherwise use WaitForChild

1 Like

the Zone1 cam is in workspace, it also returns nil when I call for it without the FindFirstChild, and the script is a local script in workspace

I also changed the FindFirstChild to WaitForChild and it kinda worked, it changed the camera bu it did not Lerp all the way through the cam CFrame

Oh yeah,I think lerps only work in server scripts ,so…