Im pretty sure you have to create a attachment since you cant rotate a attachment. Then when u get a mouse input. You do a Dot Product and check if it’s behind a player. If it is then dont run a function. But if the mouse is infront. Then run a function
Would mouse.Hit be more preferable here? A CFrame value contains both positional and rotational data about a single point in the worldspace whereas mouse.Hit is a Vector3 value which just stores positional data.
With a little bit of planning I was able to do this.
Let me share with you how.
First of all, we need a reference of what “looking forward” is…
The camera is always a good reference for this.
Then we simply need to get the angle from the dot product between the camera’s direction and the player’s direction. To get the directions, we can use CFrame.LookVector. Rather than using the current CFrame, we want to use the goal CFrame, and then only face the player to the goal if the angle is within a threshold, aka the player is facing forward.
That was my planning process. Then this is the script put together used in the video.
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Char = Player.Character or Player.CharacterAdded:wait()
local Camera = workspace.CurrentCamera
local AngleRange = math.rad(120) -- You can change this for more/less forward limiting
MouseMoveFunction = Mouse.Move:Connect(function()
local Direction = ((Mouse.Hit.p - Char.HumanoidRootPart.Position) * Vector3.new(1, 0, 1))
local Goal = CFrame.new(Char.HumanoidRootPart.Position, Char.HumanoidRootPart.Position + Direction)
local Angle = math.acos(math.clamp(Camera.CFrame.LookVector:Dot(Goal.LookVector), -1, 1))
if Angle <=AngleRange then
Char.HumanoidRootPart.CFrame = Goal
If there any problems with this let me know, but I tried to test it as much as I could for your situation. It may also help to disable Humanoid.AutoRotate if you need this while the character is moving.