What is the best way to make a gradual FOV increase when the car accelerates

As the title says, I want to achieve better gradual FOV increase when accelerating a car, as mine has a problem. I’ve looked on Youtube and DevForum, but I haven’t found anything that helps me.

This is the code I have so far, but it tweens every single frame, which is not very optimized.

local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

local VehicleSeat = script.Parent.Parent

local DefaultFOV = Camera.FieldOfView

local RenderStepped = RunService.RenderStepped:Connect(function()
	local calculation = (Engine.Velocity.Magnitude / VehicleSeat.MaxSpeed)
	
	TweenService:Create(Camera, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {
		FieldOfView = DefaultFOV * math.clamp((calculation * (0.25 / 1)) + 1, 1, 1.25)
	}):Play()
end)

VehicleSeat.Changed:Connect(function()
	TweenService:Create(Camera, TweenInfo.new(0.25, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {
		FieldOfView = DefaultFOV
	}):Play()
end)

Also, it seems that even after I stop accelerating it seems that there is a certain delay before stopping the Tween, but I don’t know how to fix it.

Edit: when he leaves the vehicle, the FOV doesn’t go down to default.

I would not use tween service. I would directly set the fov every frame—read the current speed of the seat, and then move the camera’s fov a little bit towards your target each frame.

how can i do this? Did not quite understand

In your renderstepped event instead of creating a tween every frame just move the fov in the direction you want.

One way is to like add or subtract in the direction you need:

local LERP_SPEED = 1
local RenderStepped = RunService.RenderStepped:Connect(function(dt)
  local calculation = (Engine.Velocity.Magnitude / VehicleSeat.MaxSpeed)

  local target = DefaultFOV * math.clamp((calculation * (0.25 / 1)) + 1, 1, 1.25)
  local fov = Camera.FieldOfView
  if fov < target then
    local new = fov + dt * LERP_SPEED
    if new > target then new = target end
    Camera.FieldOfView = new
  else
    local new = fov - dt * LERP_SPEED
    if new < target then new = target end
    Camera.FieldOfView = new
  end
end

As for leaving the vehicle, you’ll probably just want another variable you toggle with your seat.Changed event, and then read that inside the above loop to change target from this velocity-based thing to just the default fov

it just increases the fov, when i slow it down it doesn’t decrease.