Try this, I’ve changed the way you handled the m2 variable and a few other things that could be relevant to the issue:
local m2 = false
rs:BindToRenderStep("Viewmodel", Enum.RenderPriority.Camera.Value + 1, function()
if not tool then
return
end
if char:FindFirstChildWhichIsA("Humanoid").Health <= 0 then
if camera:FindFirstChild(tool.Name) ~= nil then
workspace.Camera:FindFirstChild(tool.Name):Destroy()
end
end
if equipped then
if camera:FindFirstChild(tool.Name) ~= nil then
local usedVM = camera:FindFirstChild(tool.Name)
local delta = uis:GetMouseDelta()
local x = clamp(delta.X, -.2, .2)
local y = clamp(delta.Y, -.2, .2)
local m2 = false
local targetCf = usedVM.Gun.Aim.CFrame
swayCF = swayCF:Lerp(cfNew(x, y, 0), .02)
usedVM:PivotTo(camera.CFrame * swayCF)
if aiming then
--camera.CFrame = usedVM.Gun.Aim.CFrame
camera.CFrame = camera.CFrame:Lerp(targetCf, 0.05)
end
end
end
end)
uis.InputBegan:Connect(function(input, gc)
if not gc then
if input.UserInputType == Enum.UserInputType.MouseButton2 then
m2 = true
end
end
end)
uis.InputEnded:Connect(function(input, gc)
if not gc then
if input.UserInputType == Enum.UserInputType.MouseButton2 then
m2 = false
end
end
end)
If you want to use :lerp then you will have to use the gun and cameras current position in the lerp not the starting position as that as you demonstrated will just make the gun/camera move a bit also whilst I am here for the lerps alpha value make sure to properly adjust for delta time like so:
omg those arms anyway after checking the code sample you sent me it looks like you scripted it correctly maybe try lerping the heads position as you mention that is related to the camera.
local aimPart = usedVM.Gun.Aim
local head:Part = usedVM:FindFirstChild("Head")
local goal = aimPart.CFrame
if m2 then
--camera.CFrame = usedVM.Gun.Aim.CFrame
head.CFrame = head.CFrame:Lerp(goal, 1-1/(dt*6+1))
Looks good maybe try increasing the multiplier on deltatime to make it a little more snappy?
Also what does leaving aim down sights look like as you need to add the lerp to both aiming down sights and un aiming down sights