How to make a FOV Changer GUI!

So this is my first tutorial, so tell me if I am doing anything wrong, but anyway, enjoy!

First, you’re going to want to add a screen GUI and put, a text box, a text label, and a text button, and a IntValue in replicated storage. name it FOV

Change the text in the button to, Press to confirm FOV! , or whatever you want it so say. Change the label to FOV Changer, or whatever you want, and leave the button empty

Then add a local script to the Text button

First, we will want to make a few variables

get the camera
get the text box
get the text button
get the int value

local textBox = script.Parent.Parent.TextBox -- gets the text box
local textBtn = script.Parent -- gets the text button
local FOVVal = game:GetService("ReplicatedStorage").FOV -- gets the FOV int value```

Then we need to detect when the button is pressed!

textBtn.MouseButton1Click:Connect(function()
	
end)

Now add the FOV’s value = to the textbox value

textBtn.MouseButton1Click:Connect(function()
	FOVVal = textBox.Text
end)

And drop a line and make the camera.FieldOfView = to the FOVVal’s value!

textBtn.MouseButton1Click:Connect(function()
	FOVVal = textBox.Text
	camera.FieldOfView = FOVVal.Value
end)

and there you have it! and FOV changer gui!

local camera = workspace.Camera -- gets the camera
local textBox = script.Parent.Parent.TextBox -- gets the text box
local textBtn = script.Parent -- gets the text button
local FOVVal = game:GetService("ReplicatedStorage").FOV -- gets the FOV int value

textBtn.MouseButton1Click:Connect(function()
	FOVVal = textBox.Text
	camera.FieldOfView = FOVVal.Value
end)

Hope this helps someone!

16 Likes

Definitely gonna bookmark this for future projects!

2 Likes

Why is FOVVal necessary? Can’t you just assign only the field of view? I even tested it out in studio and there wasn’t any issues if I edited the code to not use FOVVal.
(by the way, Activated is better to use than MouseButton1Click since it works for all control types, not just touchscreen and mouse)

5 Likes

Thanks! Def using this later! :smiley:

1 Like

just remembered why, I was making an aim thingy in my game, and having the fov go back to your set fov after your done aiming was easier to keep a value and then swap the camera

also trying to figure out how to use datastore or something to keep this to the player after they leave and rejoin

1 Like

Is there anyway to gradually make the FOV change? Sort of like using TweenPosition? The transition is so abrupt.

there probably is a way to make it do that, but I suggest maybe putting a loop or something with the value slowly going down till it hits what the player set it to

This tutorial is correct, however if the player inputs something like ‘jrnsjfjske’ that would print an error, so it would be useful to use tonumber() around the textbox.Text line.

just use tweenservice:

game:GetService(‘TweenService’):Create(workspace.CurrentCamera, TweenInfo.new(.5), {FieldOfView = number}):Play()

sorry in advance for any mistakes i am on phone.

3 Likes

Doesn’t work for me, I don’t know why