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.
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 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?
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.
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.