AlignOrientation not pointing to mouse correctly

Hi. I’m trying to make it where the player faces their mouse upon firing a gun. This is what happens.

My character will continue facing this direction, even after unequipping the weapon.

I tried making the AI (alignorientation) be set to no attachment after 5 seconds, this does not work.
Here’s the code for the AI.

	--Align character to mouse temporarily.
	local Focused = true
		while Focused == true do
			local pos = Mouse.Target.Position
			local unit = (pos - Character:FindFirstChild("HumanoidRootPart").Position).Unit
			local direction =, Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector.Y, unit.Z).Unit
			Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("Facer").PrimaryAxis = direction
			Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("Facer").SecondaryAxis = direction
			Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("Facer").Attachment0 = Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("AngularAttachment")
	delay(5, function()
		Focused = false
		Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("Facer").Attachment0 = nil

And heres the script for setting up the AI, and the attachment it runs on.

		--AlignOrientation for tools and stuff
		local Align ="AlignOrientation")
		Align.Mode = Enum.OrientationAlignmentMode.OneAttachment
		Align.Parent = char:FindFirstChild("HumanoidRootPart")
		Align.Name = "Facer"

		local Attachment ="Attachment")
		Attachment.Name = "AngularAttachment"
		Attachment.Parent = char:FindFirstChild("HumanoidRootPart")
		Align.MaxTorque = 10000
		Align.Responsiveness = 25

Any help is appreciated.

I have a 2d version of my game where my character points to the position of where the mouse is located, hopefully this helps you.

local ContextActionService = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local mouse = player:GetMouse()

local char = player.Character or player.CharacterAdded:Wait()
local Humanoid = char:WaitForChild("Humanoid")
local HumanoidRootPart = char:WaitForChild("HumanoidRootPart")

Humanoid.AutoRotate = false

camera.CameraType = Enum.CameraType.Scriptable

Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)

local cameraPart ="Part")

cameraPart.Transparency = 1

cameraPart.CanCollide = false

cameraPart.Parent = workspace

cameraPart.CFrame = +, 22, 0), HumanoidRootPart.Position)

local function onAim()
	if player.Character then
		local rootPart = player.Character:FindFirstChild("HumanoidRootPart")
		local mouseLocation =, rootPart.Position.Y, mouse.Hit.Z)
		rootPart.CFrame =, mouseLocation)

ContextActionService:BindAction("Aim", onAim, false, Enum.UserInputType.MouseMovement)

    cameraPart.Position = HumanoidRootPart.Position +, 20, 0)
    camera.CFrame = cameraPart.CFrame