The code below makes it so when you rotate the camera it spins smoothly. The only problem is that the camera keeps on spinning and it never stops. I want to add something in the script so the camera decelerates once the camera has stopped accelerating. In other words: I want the camera to slowly stop spinning instead of it spinning forever. How do I achieve this? The code below is in a local script in StarterGui.
local run = game:GetService'RunService'
local uis = game:GetService'UserInputService'
local cam = workspace.Camera
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local mult = 180/math.pi
local clamp = math.clamp
local current = Vector2.zero
local targetX, targetY = 0, 0
local speed = 0.5 -- Set the speed of the animation
local sensitivity = 1 -- Set the sensitivity of the rotation
uis.MouseDeltaSensitivity = 0.01
cam.CameraType = Enum.CameraType.Custom
run:BindToRenderStep("SmoothCam", Enum.RenderPriority.Camera.Value-1, function(dt)
local delta = uis:GetMouseDelta()*sensitivity*100
targetX += delta.X
targetY = clamp(targetY+delta.Y,-90,90)
current = current:Lerp(Vector2.new(targetX,targetY), dt*speed)
cam.CFrame = CFrame.fromOrientation(-current.Y/mult,-current.X/mult,0)
end)