A firearm moving strangely because of the locking system?

The game is combat based so i created a weapon that follows the player my goal is for the weapon to follow the player and aim the mouse and i succeeded.

as in my game there is the lock on an enemy, I wanted the weapon to target the enemy without having to use the player’s mouse, but it started to move weird, I tried to figure out how to fix it and I did not arrive.

to move the weapon and aim the mouse I used the BodyGyro and the BodyPosition, for the body Position I just create a “part” which is hooked to the player by the HumanoidRootPart and for the Body Gyro I just take the “part” position and create a rotational CFrame with the other position of the mouse in the world , For the locking I use a local script which does the same manipulation as that of the bodyGyro the only difference is which is in Local Script

=Video

Script Here

-BodyGyro on “Script”
wait(.25)
while wait() do
local targ = script.Parent.Parent.Parent.Parent.Parent.Script.TargetSystem
–The Player Locked
local char = script.Parent.Parent.Parent.Parent.Parent.Script.TargetSystem.target.Value
–mouse cframe
local mFrame = script.Parent.Parent.Parent.Parent.Parent.Script.GetMouseFrame.Frame.Value
–if locked.
if targ.target ~= targ then
script.Parent.CFrame =CFrame.new(script.Parent.Parent.Position,char.HumanoidRootPart.Position)
else
script.Parent.CFrame = CFrame.new(script.Parent.Parent.Position,mFrame.Position)
end
end

-BodyPosition on “Script”
while wait() do
local BodyG = script.Parent
local partPos = script.Parent.Parent.Parent.Position
BodyG .Position = partPos
end

–Lock Script on “Local Script”
local RunService = game:GetService(“RunService”)
local function UpdateLock()
local char2f = script.Parent.Value
local hrp = script.Parent.Parent.Parent.Parent.HumanoidRootPart

local TargVal = script.Parent.Value
--just to check if it has lock or not...
if TargVal ~= script.Parent.Parent then
	
	--put the camera in scriptable
	workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
	
	--creation of CFrame
	local hrpPos,TargetPos = hrp.CFrame.Position, char2f.PrimaryPart.Position
	local Frame = CFrame.new(hrpPos, Vector3.new(TargetPos.X, hrpPos.Y, TargetPos.Z))
	local CamFrame = Frame*CFrame.new(0, 6, 14)
	
	--put the Cframe in action ;)
	workspace.CurrentCamera.CFrame = CamFrame
	hrp.CFrame = Frame
else
	workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
end

end
RunService.RenderStepped:Connect(UpdateLock)