When player resets custom camera starts stuttering

I have a camera that uses delta time to make the look consistent between frame rates but when the player resets the camera starts to stutter badly heres my code:

function updateCam(DeltaTime)
    Accumulated += DeltaTime
    while Accumulated >= Rate do
        Accumulated -= Rate
        subject.Position = subject.Position:Lerp(Vector3.new(torso.Position.X - Vals['.XOffset'].Value,torso.Position.Y + Vals['.Height'].Value,torso.Position.Z - Vals['.ZOffset'].Value),1/Vals['.Weight'].Value)
        subject.CFrame = subject.CFrame:Lerp(CFrame.fromOrientation(math.rad(Vals['.X'].Value),math.rad(Vals['.Y'].Value),math.rad(Vals['.Z'].Value)) + subject.Position, (1 / Vals['.Weight'].Value))
        cam.CameraType = Enum.CameraType.Scriptable
        cam.CFrame = subject.CFrame
        cam.FieldOfView = 15
    end

end

local connect = RunService.RenderStepped:Connect(updateCam)
Character.Humanoid.Died:Connect(function()
    connect:Disconnect()
end)

Heres video of what happens

I found this devforum post but i dont understand how to interpret the solution: Major camera stuttering when lerping to an object (delta time issue) - #14 by plasma_node

1 Like

I still havnt figured out a solution

To save you some trouble, why not just disable the camera update upon death? or add some sort of Death Screen to hide the ‘bug’? a death screen that will act as like a loading screen that only goes away after you respawned

You realize that while loop is being executed every frame right? Even when the connection is disconnected those loops will continue to run.

1 Like

as @Forummer implied I didn’t see it till he pointed it out, you should remove the while loop as runservice is already a loop itself, you’re creating a massive memory leak if that’s left un-attended/not handled well.

thank you, i changed the while loop to an if statement and its working now

1 Like