How can I change the direction to which a player is looking while that player is in the first person and I tried with cframe and it does not work, does anyone help me?
One way to achieve this would be through the use of camera manipulation.
From a LocalScript, you can obtain a player’s camera through the following code.
local camera = workspace.CurrentCamera
The camera comes with a set of powerful properties for you to edit orientation, allowing you to face the camera at your intended target. One of such properties is the CFrame property.
The following code is a simple script that keeps a player looking at the world coordinate (0,0,0) using CFrames and camera manipulation.
--LocalScript placed in StarterPlayer.StarterPlayerScripts
local camera = workspace.CurrentCamera --Acquires the local camera
local position = Vector3.new(0,0,0) --Sets a position to look at (can be changed)
camera.CameraType = Enum.CameraType.Scriptable --Changes the camera type to scriptable (this is good practice when scripting your own camera functions)
game:GetService("RunService").RenderStepped:Connect(function() --A function that fires every frame (many times per second)
camera.CFrame = CFrame.new(camera.CFrame.p, position) --Uses CFrame to orient the camera toward the established position
end)
If you are having trouble with understanding the CFrame part, note that I am simply using the format CFrame.new(position vector, look vector), with the position vector being where the CFrame is stationed and the look vector being a direction/position for the CFrame to orient towards.
The idea of camera manipulation can be very tricky, so I suggest you take a look at the following articles for more details.
If you have any further questions, do not hesitate to ask them! Also take note that there are multiple ways to achieve this, so keep an open mind to any other possible ideas.