Tweening Viewmodel Relative to Camera

I’m working on making an item bob back and forth slightly in the players hand while they walk. So far I have something basic that works fairly well, but the problem is the transition: When the player first starts moving or stops moving the object snaps back to the starting /ending position respectively. I believe my solution will be to use tweens so it smoothly glides to those positions first. You will see my attempt at this below:

function viewmodelBob()
    local currentCF = cam.CFrame*,spin)
    local t = tick()
    local humanoid = player.Character:FindFirstChild("Humanoid")
    if humanoid.MoveDirection.Magnitude > 0 then
        local y = math.abs(math.sin(t * 5)) * 0.15
        local z = math.cos(t * 5) * 0.15
        local cf = currentCF *, y, z)
        viewmodel.CFrame = cf
        viewmodel.CFrame = cam.CFrame*,spin)
        local goal = {}
        goal.CFrame = cam.CFrame*,spin)
        local tweenInfo =
        local tween = TweenService:Create(viewmodel,tweenInfo,goal)
    if HitPoint then att1.WorldPosition = HitPoint end

Instead of moving the part relative to the camera smoothly and beautifully the viewmodel just gets locked in whatever position it started for the duration of the tween before reverting to normal bobbing back and forth.


i suggest you to use lerp, it’s like using the method for camera bobble but for fps