I want to recreate the gun-sway from these following posts; but have been unsuccessful in doing so, to do achieve this I need to unlock the gun from the center of the screen but I am struggling to put it together to make it work well since this is my first gun system.
This is a snippet of the code I am using (very messy but I will redo it after I get a solution)
local deltaCF = CFrame.new(-MouseDelta.x/200, MouseDelta.y/200, 0)
deltaCF = CFrame.new(math.clamp(deltaCF.x , -0.2, 0.2), math.clamp(deltaCF.y , -0.2,0.2), math.clamp(deltaCF.z, -0.2,0.2))
local CameraOffset = CurrentCamera.CFrame:ToWorldSpace(CFrame.new(Vector3.new(0, -1.65, -1)))
local lastCameraCF = CurrentCamera.CFrame
local swayOffset = lastCameraCF
local rotation = workspace.CurrentCamera.CFrame:toObjectSpace(lastCameraCF);
local x, y, z = rotation:ToOrientation();
swayOffset = swayOffset:Lerp(CFrame.Angles(math.sin(x)*6, math.sin(y)*6, 0), .1)
Viewport.HumanoidRootPart.CFrame = swayOffset
lastCameraCF = CurrentCamera.CFrame
Viewport.HumanoidRootPart.CFrame = NewOffset