Issue with Camera Orientation Not Updating on Respawn

Hey everyone,

I’m trying to modify the camera orientation when a player respawns.

I placed a LocalScript inside StarterCharacterScripts, so it runs automatically after the player respawns. The script is supposed to rotate the camera to (0, -90, 0) on the world axis, but for some reason, it doesn’t work.

Here’s my LocalScript in StarterCharacterScripts:

local currentCam = workspace.CurrentCamera
currentCam.CFrame = CFrame.new(currentCam.CFrame.Position) * CFrame.Angles(0, math.rad(-90), 0)
  • No errors in output

  • I suspect the camera might not be fully initialized when the script runs? I don’t know

Does anyone know why this happens and how to fix it?

Would appreciate any help! :rocket:

You’re correct here.

You can try adding a task.wait() of around 0.2-0.4 seconds. If that doesn’t work try changing the CameraType to Scriptable and then back to Fixed.

Solution: Added a Delay as Suggested

I did what you suggested and added task.wait(0.2) at the beginning of my script. Now it looks like this:

task.wait(0.2) -- Waits 0.2 Seconds before the Camera changes.
local currentCam = workspace.CurrentCamera
currentCam.CFrame = CFrame.new(currentCam.CFrame.Position) * CFrame.Angles(0, math.rad(-90), 0)

It works now! Looks like the issue was the camera not being fully initialized.

Thanks a lot for the help! :blush:

No worries! Just keep this in mind that it takes a few milliseconds for the camera to properly initialize. Around 2-4 frames but I recommended 0.2 seconds just to be on the safe side. :slight_smile:

1 Like

Wait, then instead of adding a delay I could do this?

local RunService = game:GetService("RunService")

-- Wait 4 frames before chaning the Camera
RunService.RenderStepped:Wait()
RunService.RenderStepped:Wait()
RunService.RenderStepped:Wait()
RunService.RenderStepped:Wait()

local currentCam = workspace.CurrentCamera
currentCam.CFrame = CFrame.new(currentCam.CFrame.Position) * CFrame.Angles(0, math.rad(-90), 0)

Because you said it takes 2-4 frames, so I just wait until 4 frames are rendered?
I also tested this script, and it works!

Yes, you can but literally doing that is a bit too inefficient. A better thing to do is just to add a task.wait(0.1) which is roughly 6 frames would work as well.

Adding 4 RunService just won’t look good for any on-lookers and may raise eyebrows as it’s not the norm.

Okay Thanks,

then I’ll do task.wait(0.2)
because It is more efficient.

No worries! Happy developing! :smiley:

1 Like