Camera manipulation not working at all

So I was using the code here at the bottom but it is behaving extremely unusually. I have read several similar posts, but the writers never say what fixed it or they resort to some non-conventional method using loops or something and I don’t want to use that. When I run the code, my camera appears to be in the middle of nowhere, and when I print the position it says “-nan(ind), -nan(ind), -nan(ind)” and I have no idea what that means. It looks like the camera type is set correctly, but the position does not get set and I don’t why or how to fix it.

Code:

cam = workspace.CurrentCamera
camPart = workspace.CamPart

cam.CameraType = Enum.CameraType.Scriptable
cam:GetPropertyChangedSignal("CameraType"):Wait() --I am aware that roblox changes the camera type shortly after the player joins, so I am waiting for that to happen then setting it again
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = camPart.CFrame --This line specifically does not seem to work since the camera appears in the middle of nowhere

If you think you know why this isn’t working I’d like to hear!

nan means Not A Number and ind means indefinite which means that the values are undefined (eg, you would get nan(ind) by dividing 20 / 0 and printing it). You should set the camPart.CFrame to an actual CFrame value.

But shouldn’t the last line set the camera to an actual CFrame? It says cam.CFrame = camPart.CFrame

Instead of using Wait() and yielding the script before changing the CFrame, try using Connect instead.

have you made sure the part has loaded in prior to the script setting its cframe??

You’re setting cam.CFrame to camPart.CFrame. You’re not setting camPart’s original CFrame, you’re just moving a totally different object to camPart’s CFrame (which is undefined, hence why it prints nan(ind))

I haven’t, I can try it though. Also, shouldn’t it have an error if the part isn’t loaded in?

The wait was just for making sure the camera type was set correctly. I don’t think it has to do with my issue.

I don’t think I understand this. The camera’s CFrame value is being set to the same CFrame value as that of the part. Why wouldn’t it work? And do I need a new CFrame object?

You’re moving cam to camPart:

However, since camPart’s CFrame is undefined, that means that you’re moving cam to practically no location which glitches it out.

You can fix this by setting camPart.CFrame to an actual CFrame. I don’t get why it’s hard to understand.

That makes sense now, but why is camPart’s CFrame undefined? And how am I supposed to make it an actual CFrame? It’s just an ordinary part in the workspace.

Can you run a quick play session and tell me if camPart is actually still there and isn’t in oblivion?

I can’t access my computer at the moment but I am sure it is there and fine. I haven’t done anything with it. I think the issue is actually what someone else mentioned which is that the part might not be loaded yet since this happens locally almost as soon as the game begins.

It turns out the part was in oblivion I guess. For some reason when the part first loads it gets placed in the middle of nowhere, so I just made the camera CFrame be the part’s CFrame every frame using RunService.RenderStepped, and it eventually put the camera in the right place.

1 Like