Trying to make a Max Range for Field of View

Hello! I’ve been trying to figure out how to find a max range for a Camera FOV, but I have no clue on what I should be trying, I want to make it where there’s a range for only to 70-120 for the camera effect but I end up breaking the camera with out any clue.

The whole coding for it is this.


UserInputService.InputChanged:Connect(function()
	if Dragging ~= false and Inside ~= false then
		local MousePosition = UserInputService:GetMouseLocation()
		local RelatedPosition = MousePosition - Frame.AbsolutePosition
		
		local Percent = RelatedPosition.X / Frame.AbsoluteSize.X
		
		TweenService:Create(Button,TweenInfo.new(1),{Position = UDim2.new(math.clamp(Percent, 0, 1),0 ,0.5 ,0)}):Play()
		TweenService:Create(CurrentCamera,TweenInfo.new(1),{FieldOfView = Percent*95}):Play()
		
		for _, CameraText in pairs(Frame:GetChildren()) do
			if CameraText:IsA("TextLabel") then
				CameraText.Text = CurrentCamera.FieldOfView
			end
		end
	end
end)

This is a slider button, so I’m a bit confused, if there’s any site I should check out or video let me know please, I’ve been trying to figure it out for the past 2 hours trying to make a max range for the Field of View.

1 Like

Hello! I have created a simulation of your scenario. Unfortunately, there is so much to explain here, I’ve decided not to go in detail here, but rather through comments in the code. If you have any questions, let me know.

Note: If you are confused about the UDim2 position values I chose, note that the AnchorPoint of Slider is 0.5, 0.5.

The file: FOVSlider.rbxl (37.9 KB)

Here is a video of the code in action!

Again, if you have any questions or concerns, let me know! If you’re interested, my discord tag is jamston#1608. You can add me there if you have more immediate questions you want to discuss.

Hope this helps!

https://developer.roblox.com/en-us/api-reference/property/Camera/FieldOfView

The default is 70 degrees & the range it’s clamped between is 1 and 120 degrees inclusively.