Camera CFrame doesn't set correctly

Basically what this code is meant to do is set the camera type to scriptable and set the camera cframe to a part’s cframe.
The issue is that instead of setting the camera’s cframe to the part’s cframe it just makes the camera look in the direction that the part is facing.
I’ve made sure the part is anchored and that the code is written right and I’ve even tried putting it in a while loop but it still only sets the camera to look in the direction the part is facing
Every post on the devforum I can find is either not similar enough to what I’m experiencing or they had the issue because of a mistake in their coding.

local player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
game.ReplicatedStorage.HouseEXPL.OnClientEvent:Connect(function()
	player.CameraMode = Enum.CameraMode.Classic
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = workspace.ShakeCutscenePart.CFrame
	print("success")
end)

Edit: So I’ve tried making it a tween and the tween moves it to the position and then as soon as its done it snaps it right back

3 Likes

Right click on the part, click “Show Orientation Indicator”, click it, and find the direction it is facing. Setting the camera’s CFrame to a part’s CFrame will make the camera look the same direction the front surface is.

Turning on the orientation indicator will show you the front surface. Rotate the part accordingly to where you want it to go.

Uhhhh you read the post right?

Are you saying the camera is facing the wrong way when it sets it to the position?

English isn’t my first language. It’s kinda confusing.

I’m saying that it doesn’t set the position at all

Try removing player.CameraMode = Enum.CameraMode.Classic.

I don’t believe you will need to change the camera mode while scripting it. If this doesn’t solve the problem, let me know.

Also a tip,
If you’re printing success, wrap your function in a pcall like this:

local success  = pcall(function()

end)
if success then
    print("Success")
end

The way you set it made it sound as if it set the position but was facing the wrong way. My bad.


I would remove player.CameraMode = Enum.CameraMode.Classic and see if that works.

It still didn’t work, also for some reason it still prints success

Why would this help?..

The script would return an error either way if it’s indexing for a child before it exists, and cleary that isn’t their problem.

The script still prints success because (assuming you wrapped the function in a pcall correctly) there’s nothing in your script that is causing any errors.

Are you running this script on the client, or the server? When exactly is it applying these changes? (e.g. when the server starts, when the character loads, etc.)

Client, It applies the changes when a proximity prompt fires a remote event in replicated storage

Testing your code in a local script, everything seems fine.

As long as your code is running at the right time, and isn’t conflicting anything else that may be manipulating the camera, you shouldn’t have any problems.

Ensure that the part in question is anchored and in the correct position before this code runs. If you’re still confused and unable to solve the problem, please show me the code in your server script as well as the part you are using the CFrame of.

Screenshot_24
Screenshot_25
Screenshot_26

Hm, interesting.

Can you show me what the camera looks like after the code runs, and where ShakeCutscenePart is in the workspace?

The camera is locked to this angle


and the part is just in workspace its not parented to any other parts

Do you have any error outputs in the console?

Is this the position and rotation of the part, or is it somewhere else?

No
I seriously despise this text limit

1 Like

The part is somewhere else but this is the angle it faces

Sometimes the camera type doesn’t set all the time, so you could try this.

local Storage = game:GetService("ReplicatedStorage")

local Plr = game:GetService("Players").LocalPlayer
local Camera = workspace.CurrentCamera

Storage.HouseEXPL.OnClientEvent:Connect(function()
    repeat
        Camera.CameraType = "Scriptable" -- yes you can use strings to set it, but not when checking it

        task.wait() -- prevent lag
    until Camera.CameraType == Enum.CameraType.Scriptable

    Camera.CFrame = workspace.ShakeCutscencePart.CFrame
end)