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.