Having trouble changing the camera's rotation

It’s such a simple thing to do but for some reason it’s just not working.

So when you first spawn in (or at least in my case), the camera’s Orientation X is -15 degrees. I want this value to be 0, so naturally I made a script to change the angle.

I’ve made a LocalScript in StarterCharacterScripts and done the following:

local camera = workspace.CurrentCamera
camera.CFrame *= CFrame.Angles()

I thought that maybe it’s adding 0 instead of setting it to 0, so I changed the script to the following:

local camera = workspace.CurrentCamera
camera.CFrame *= CFrame.Angles(math.rad(15),0,0) --this should cancel out the rotation

Neither of these work. I thought that maybe something was interfering with the script, so I also added code to change the CameraType to Scriptable before changing rotation. That didn’t work either. I also tried putting the script in StarterPlayerScripts instead but that also did nothing.

Weirdly enough, the above script did work when I bound it to the H key using UserInputService (it panned the camera up 15 degrees every time I pressed it).

Why can’t I change the camera angle here, and how do I do so?

Two things:

  1. Yes, my script was adding to the camera angle instead of just setting it. If you want to set the angle, you do this:
local camera = workspace.CurrentCamera
camera.CFrame = CFrame.new(camera.CFrame.Position) * CFrame.Angles(0,0,0)
  1. The camera doesn’t get set because it hasn’t loaded yet. I tried using PreloadAsync to ensure the camera loaded first, but even that didn’t work. I had to resort to the good old “repeat until”
repeat wait() until game.Workspace:FindFirstChild("Camera") 

Now my script works as intended.

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