Weird lerp glitch when trying to assign cframe to it?

i’m working on an fps project where players control their firearms through their viewmodel on the client side,
back then the model keeps snapping to different positions as you move around and that appeared to be lame so i wanted to keep it moving, transitioning smoothly between different stances
i tried using lerp and it worked great (with slight stuttering) and it also gave me the swaying motion which i also wanted to implement but hadn’t known how, however setting its cframe to lerp gives this really weird glitch that happens for the first few to 10+ seconds and then works as intended afterwards
looking for solutions was difficult as i didnt know why it was this way so i came to the devforum after asking manywhere

tldr: title

this is a snippet of the script which handles the viewmodel:

local repStorage = game:GetService('ReplicatedStorage')
local runService = game:GetService('RunService')

local gunAnims = repStorage.GunAnims

local modules = repStorage.Modules

local firearmsFolder = game.ReplicatedStorage.Guns

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

local vm = char:WaitForChild('Viewmodel')

local hum:Humanoid = char.Humanoid
local fakeHum:Humanoid = vm.Humanoid

local Viewmodel = {
	Player = plr,
	Model = vm,
	Sprinting = false,
	BobData = {
		BobCounter = 0,
		BobAmount = Vector3.new(0.15, 0.075, 0),
		BobSpeed = 6
	}
}

Viewmodel['Viewmodel Camera Handler'] = runService:BindToRenderStep('ViewmodelCam', Enum.RenderPriority.Camera.Value + 1, function(dT)
	local fakeCam:BasePart = vm.FakeCamera
	local cam = workspace.CurrentCamera
	
	local Sprinting = Viewmodel.Sprinting
	local BobData = Viewmodel.BobData
	local Amount = BobData.BobAmount
	local Speed = BobData.BobSpeed
	
	for _, part in vm:GetDescendants() do
		if part:IsA("BasePart") then
			part.LocalTransparencyModifier = 0
		end
	end

	vm["Left Arm"].CanCollide = false
	vm["Right Arm"].CanCollide = false
	
	if hum.MoveDirection.Magnitude > 0 then
		local baseCFrame = CFrame.new(0, 0, 0)
		local moveMagnitude = hum.MoveDirection.Magnitude
		BobData.BobCounter = BobData.BobCounter + moveMagnitude * dT * Speed
		
		local bobX = math.sin(BobData.BobCounter) * Amount.X
		local bobY = math.sin(BobData.BobCounter * 2) * Amount.Y
		local bobOffset = fakeCam.CFrame:VectorToWorldSpace(Vector3.new(bobX, bobY, 0))
		local sprintOffset = Vector3.new(0, -0.4, 0)
		local bobCFrame = cam.CFrame + bobOffset
		local bobSprintCFrame = cam.CFrame + bobOffset + cam.CFrame:VectorToWorldSpace(sprintOffset)
		
		if hum.WalkSpeed <= 18 then
			fakeCam.CFrame = (fakeCam.CFrame:Lerp(bobCFrame, 0.4))
		else
			fakeCam.CFrame = (fakeCam.CFrame:Lerp(bobSprintCFrame, 0.4))
		end
	else
		fakeCam.CFrame = (fakeCam.CFrame:Lerp(cam.CFrame, 0.4))
	end
end)

the youtube video below shows the glitch…

just anchor viewmodel already :skull:
It keeps gaining momentum every time

Like @Yarik_superpro said, just select the model and anchor it. Else you can just script it in yourself:

for _, descendant in pairs(vm:GetDescendants()) do
   if not descendant:IsA("BasePart") then continue end
   descendant.Anchored = true
end

is that why it kept bouncing up and down

i anchored the viewmodel’s humanoidrootpart (other parts in the model are welded to it) and it stopped glitching like in the video so apparently it worked
i have a question though, why did that happen? how was physics only affecting the viewmodel for seconds before stopping??

I think your fps is changing from low to high so the lerp increases in strength and it manages to lift the viewmodel back up
use Lerp(End, 1 - 0.001 ^ DeltaTime) to fix this

tried doing this without anchoring, the viewmodel still fell and the sway was just really (too) smooth

The viewmodel is probably owned by the server at first so moving it on the client makes it weird so read this Network ownership | Documentation - Roblox Creator Hub
also increase the amount of zeroes in lerp to make the sway less smooth

i read some stuff and toggled on the debug view for network ownerships… at first it was client owned but then as it snaps back into the place intended it becomes server-owned after some time
the viewmodel was not anchored at that time, weird considering how stuff can be super far from the char and still be client owned

Studio client ownership is weirder than the actual roblox app so it can do that sometimes

well tysm i understood why that happened now!!