How to fix field of view?

local Userinput = game:GetService("UserInputService")
wait(1)
local parent = script.Parent
local slider = script.Parent.sliderButton.Slider
local u1 = false
function GrabFOVKnob()
	u1 = true
end
local Currnetcamera = workspace.CurrentCamera
local positionk = slider.Parent.Knob
local fovalue = script.Parent.FOVValue
function MoveFOVKnob(p1)
	local v4 = math.min(math.max((p1.y - slider.AbsolutePosition.y) / slider.AbsoluteSize.y, 0), 1)
	local v5 = 20 + 100 * (1 - v4)
	Currnetcamera.FieldOfView = v5
	positionk.Position = UDim2.new(1, 0, v4, 0)  
	fovalue.Text = math.floor(v5)
end
function ReleaseFOVKnob()
	u1 = false
end
positionk.InputBegan:connect(function(p2)
	if p2.UserInputType == Enum.UserInputType.MouseButton1 or p2.UserInputType == Enum.UserInputType.Touch then
		GrabFOVKnob()
	end
end)
Userinput.InputChanged:connect(function(p3, p4)
	if not p4 and ((p3.UserInputType == Enum.UserInputType.MouseMovement or p3.UserInputType == Enum.UserInputType.Touch) and u1) then
		MoveFOVKnob(p3.Position)
	end
end)
Userinput.InputEnded:connect(function(p5, p6)
	if not p6 and p5.UserInputType == Enum.UserInputType.MouseButton1 or p5.UserInputType == Enum.UserInputType.Touch then
		ReleaseFOVKnob()
	end
end)

robloxapp-20220513-1909358.wmv (1.4 MB)

I have tried everything but can not figure what is wrong can anyone help me please. Thank you!

You could use math.clamp so it doesn’t go above or below the amount you set.

Which line exactly? and will it help to fix the script?

I’m not really sure what v4 and v5 is but there are some errors I can see.

positionk.Position = UDim2.new(v4, 0, 1, 0) as you can see you were changing the Y instead of the X.

As for math.clamp you add it to the v4 so it should look like this local v4 = math.clamp(p1.x - slider.AbsolutePosition.x) / slider.AbsoluteSize.x. 0, 1)
You need to change the Y to and X since you want it to go left to right instead of up and down

Hmm, it is still not working, but I am pretty close to fix it. If you do not mind, can you please edit and reply the script please.

function MoveFOVKnob(p1)
	local v4 = math.clamp((p1.x - slider.AbsolutePosition.x) / slider.AbsoluteSize.x, 0, 1)
	local v5 = 20 + 100 * (1 - v4) 
	Currnetcamera.FieldOfView = v5
	positionk.Position = UDim2.new(v4, 0, 1, 0)  
	fovalue.Text = math.floor(v5)
end

What is happening now?

1 Like

I fixed it. Thanks a lot for helping!

1 Like