How to change player's camera rotation?

Hello!
So, I’m making an obby and it has stages. Whenever a player dies, they are teleported back to that stage. I don’t know how to change their camera rotation because it is turned in the opposite way as they should continue the obby.
How would I do that?

Thank you!

1 Like

Could you possibly make the camera’s CFrame, it’s position with the lookAt being the character’s HumanoidRootPart’s LookVector?

For example:

local player = game:GetService("Players").LocalPlayer
local camera = workspace.CurrentCamera

camera.CFrame = CFrame.new(camera.CFrame.Position, player.Character.HumanoidRootPart.CFrame.LookVector)
6 Likes

Should that be server or local script + if local, where should I put it?

You should put it in a local script, in the startergui.

1 Like

Since it’s using the LocalPlayer, it has to be a LocalScript.
Where you put it is up to you really, I’d prefer StarterCharacterScripts since it’ll run when they spawn.

Im pretty sure just rotating the spawn location 180 degrees should solve the problem.

It’s not about the spawn location. Stages (checkpoints) are just normal parts.

It returns

HumanoidRootPart is not a valid member of Model

I put it in StarterGui.

Ah I hoped that wouldn’t happen.
You’ll need to :WaitForChild when getting the Humanoid

Ok. I’m not getting the error anymore, but it seems it’s not working (it doesn’t turn the camera)

Remember that it only runs once, unless it’s in a ScreenGui with ResetOnSpawn on.
This is why I recommended StarterCharacterScripts.

Ok. Did it, but it turns the camera only sometimes, not always.
Oh, I put the wait() above the code and it seems to be working now, but, is there any other way to fix that problem?

Not really, it’s to do with the camera and how it’s re-positioned when you spawn.

In Robloxs template obby it doesnt use a spawn location just like yours and uses a decal to indicate its a checkpoint and uses a script inside it in which if u touch it you now spawn there. You can find it if you go on studio and click + new then All Templates then Obby

nvm just checked it only works sometimes

Thank you so much!
Optional thing: is there any way to make the camera to be a little bit above the character, not behind it. And also, it’s not really centered.

I’ll check that later, thank you!

For that you’d need to change the CFrame to the HumanoidRootPart’s CFrame + some offset.
You’ll get the Orientation from the HumanoidRootPart’s CFrame by doing this.

For example:

wait()
local player = game:GetService("Players").LocalPlayer
local camera = workspace.CurrentCamera
local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")

camera.CFrame = humanoidRootPart.CFrame * CFrame.new(0, 2, 1) --// 2 Y axis offset + 1 Z axis offset
5 Likes

so theres another solution, just rotate the spawn or checkpoint

It’s easier to make your camera’s rotation adapt to the spawn’s cframe instead of adapt how many spawns your game has just to the camera

2 Likes