FOV depending on car speed script not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make the fov of the player change depending on the amount of speed the car has.
    (to achieve a sense of speed, basically)

  2. What is the issue? Include screenshots / videos if possible!
    i tried making a script so it changes the fov based on what i talked above (car speed), but it didnt work.
    here are the scripts:

local cam = game.Workspace.CurrentCamera

while true do
	local MaxSpeed = script.Parent.MaxSpeed
	local CurrentSpeed = script.Parent.Velocity.Magnitude
	wait(.2)
	cam.FieldOfView = ((CurrentSpeed / MaxSpeed) * 70) + 70			
end

^
this one is inside the car.

local cam = game.Workspace.CurrentCamera

cam.CameraType = Enum.CameraType.Scriptable

^
and this one is to change the camera type to scriptable, its located in the workspace

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I searched around many posts in here, but none of them were helpful since it wasnt what i was looking for.

the math is also made so you cant go below 70 of FOV, but cant go beyond 140, but other than that i cant get my head around any idea as of why this isnt working.

i also tried doing a simple test to see if the fov of the camera changed with scripts:

wait(5)
workspace.CurrentCamera.FieldOfView = 140

but it somehow didnt work either.

1 Like

Is this a local script or a server script? You should be changing the FOV within the client. Example: (Client script)

local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera

Camera.FieldOfView = 140 

1 Like

it was a server sided script, i also tried it with a local one but it didnt work either

1 Like
local cam = workspace.CurrentCamera
local car = path.to.car

local RunService = game:GetService("RunService")

local function render()
   if cam.CameraType ~= Enum.CameraType.Scriptable then
      cam.CameraType = Enum.CameraType.Scriptable
   end

   local maxSpeed = car.MaxSpeed.Value -- I suppose this is a NumberValue
   local currentSpeed = car.Velocity.Magnitude
   cam.FieldOfView = ((currentSpeed / maxSpeed) * 70) + 70
end

RunService.RenderStepped:Connect(render)

Make sure this is a local script, and make sure it’s in one of these locations: StarterPlayerScripts, StarterGui, StarterPack, e.t.c

my camera is now stuck in one place when i tried this

ok nevermind after some changing in the code the camera is no longer still, BUT the fov isnt changing at all

@vouthin just make it custom camera

i did try this but it didnt work either.

i also noticed that i kept getting an error on the output:


and just in case, this is how the car is organized:
image