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)
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.
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.
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.
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