Fov based on vehicle speed

Hello! I tried scripting a fov changer that would be based on the vehicle speed, that its using a-chassis and i took advantage of a plugin that has speed gauges and has a textbutton that shows the speed, so fieldofview = speed.text, but that seems that its not doing anything

i made a localscript on the starterplayerscripts and its the following

local playerGui = game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')
local humanoid = game:GetService("Players").LocalPlayer:WaitForChild("Character"):WaitForChild("Humanoid")
local camera = workspace.CurrentCamera

for _, speed in pairs(playerGui:GetChildren()) do
	if speed:IsA("TextButton") and speed.Name == "Speed" then
		local minFov = 70
		local maxFov = 120
		
		if humanoid.Sit == true then
			camera.FieldOfView = speed.Text
			
			if camera.FieldOfView <= minFov then
				camera.FieldOfView = minFov
			end
			if camera.FieldOfView >= maxFov then
				camera.FieldOfView = maxFov
			end
		end
	end
end
1 Like

You’re making the field of view a string. convert the text to an integer with tonumber()

Ex: camera.FieldOfView = tonumber(speed.Text)

Also, The only children of player gui can be screen Gui. Essentially ruining your if statement. Try “GetDescendants” or try to specify more into the children.

sorry for late response it was midnight but tried that its happening the same thing, nothing happens

local playerGui = game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')
local humanoid = game:GetService("Players").LocalPlayer:WaitForChild("Character"):WaitForChild("Humanoid")
local camera = workspace.CurrentCamera

for _, speed in pairs(playerGui:GetDescendants()) do
	if speed:IsA("TextButton") and speed.Name == "Speed" then
		local minFov = 70
		local maxFov = 120
		
		if humanoid.Sit == true then
			camera.FieldOfView = tonumber(speed.Text)
			
			if camera.FieldOfView <= minFov then
				camera.FieldOfView = minFov
			end
			if camera.FieldOfView >= maxFov then
				camera.FieldOfView = maxFov
			end
		end
	end
end

Do prints for each for and each if statement to see if it prints something.

I know I’m 3 years late but if you’re still looking for this (you probably aren’t) I made one the other day as a bonus you can mark this post as solved after all these years. Anyway, if you wish to set a min and max fov you could clamp the values using math.clamp.

This is a local script that goes in the a-chassis plugins folder

Script:

local car = script.Parent.Car.Value
local cam = workspace.CurrentCamera
local RS = game:GetService("RunService")
local OldField = cam.FieldOfView

car.DriveSeat.ChildRemoved:connect(function(child)
	cam.FieldOfView = OldField
end)

RS.RenderStepped:Connect(function()
	cam.FieldOfView = OldField + car.DriveSeat.Velocity.magnitude / 3 -- Change this value to increase or decrease the intensity of the effect.
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.