Part facing to the camera

Hello, guys i need help.

So, i want the Part to face to the Camera of player that where he/she facing to. Please give me an example of script thank you.

local Player = game.Players.LocalPlayer

game:GetService("RunService").RenderStepped:connect(function()

local Camera = workspace.CurrentCamera

workspace.Part.CFrame = CFrame.new(workspace.Part.Position) * CFrame.fromOrientation(math.rad(Camera.CoordinateFrame.X), math.rad(Camera.CoordinateFrame.Y), math.rad(Camera.CoordinateFrame.Z))

end)
2 Likes

You should read the Guidelines for posting in Scripting Support before posting.

What methods did you try already?

2 Likes

Let me re-edit my post i forgot to add the script.

1 Like

A post was merged into an existing topic: Off-topic and bump posts

You’re overcomplicating it.
If you go to CFrame Wiki Page, you can see that CFrames can be created in few ways.

One of them being:

CFrame.new(Vector3 pos, Vector3 lookAt)

In your case pos is the Part’s position, and lookAt is camera’s position.
It will return a CFrame located a Part’s position, which looks towards camera’s position.

6 Likes

So it’s not same? CFrame.new(CurrentPos) * CFrame.fromOrientation(math.rad(X), math.rad(Y), math.rad(Z))

1 Like

According to wiki, CFrame.fromOrientation does:

CFrame.fromOrientation(number rX, number rY, number rZ)
Creates a rotated CFrame using euler angles ( rX , rY , rZ ) in radians. Rotations are applied in Z, X, Y order.

It means that it just creates a blank CFrame with rotation defined by rX, rY and rZ. All of those are meant to be radians.

Tl;dr: No, it’s not the same thing.

3 Likes

No. That’s not what Scripting Support is for.


As Legoracer stated, there are two arguments for CFrame; one that specified the position and another to determine where it points towards. Just want to highlight that in simpler terms, as well as for anyone else who views this thread with this question.

Out of curiosity, what is your use case for this?

2 Likes

CFrame.fromOrientation(math.rad(Camera.CoordinateFrame.X), math.rad(Camera.CoordinateFrame.Y), math.rad(Camera.CoordinateFrame.Z))

This part is unnecessary, and it’s using the wrong information given what you’re trying to accomplish. Camera.CoordinateFrame is just a CFrame, so it’s X/Y/Z properties represent the components of it’s position, not rotation. The rotation components of a CFrame are a little more complicated.

If you do want easy values for the rotation of a CFrame you can use local rx, ry, rz = cframe:toEulerAnglesXYZ() but I would advise against it. They’re fine for debug purposes but you’ll get much more accurate results by calculating the values for yourself.


CFrame.new(workspace.Part.Position) is a step in the right direction. As mentioned the CFrame constructor can accept 2 Vector3 values to create a CFrame that is positioned at the first Vector3, looking towards the second Vector3.

So in your use case building a CFrame to look at the camera from a parts position would look like

part.CFrame = CFrame.new(part.Position, camera.CFrame.p)

10 Likes