FOV Value Won't Stay!

I’m trying to make a gun system where if you equip your weapon, you can right click to zoom in, and release right click to zoom back out.

For some reason, when I right-click, the FOV changes, but the FOV won’t stay the same value, it just resets back to 70! I wanted it to stay at 20!

The script Detects if the tool the player is holding has a bool value, so the script runs.

Basically, how do I keep the FOV the same value (20) until the player stops right clicking?

This script was placed in StarterPlayerScripts:

local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Mouse = Player:GetMouse()

local TS = game:GetService("TweenService")
local info = TweenInfo.new(0.1,Enum.EasingStyle.Sine,Enum.EasingDirection.Out)

local MouseDown = false

Mouse.Button2Down:Connect(function()
	if Character:FindFirstChildWhichIsA("Tool"):FindFirstChild("IsWeapon").Value == true then
		if MouseDown == false then
			Mouse = true
			local Tool = Character:FindFirstChildWhichIsA("Tool")
			local Goal = {FieldOfView = 20}
			local TweenIn = TS:Create(Camera,info,Goal)
			TweenIn:Play()
			wait(0.1)
			Camera.FieldOfView = 20 ------Problem
		end
	end
end)

Mouse.Button2Up:Connect(function()
	if Character:FindFirstChildWhichIsA("Tool"):FindFirstChild("IsWeapon").Value == true then
		if MouseDown == true then
			MouseDown = false
			local Tool = Character:FindFirstChildWhichIsA("Tool")
			local Goal = {FieldOfView = 70}
			local TweenOut = TS:Create(Camera,info,Goal)
			TweenOut:Play()
		end
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Turns out it was another script Interfering with this script. Problem Solved!

Here’s the final script for anyone who wants it!

local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Mouse = Player:GetMouse()

local TS = game:GetService("TweenService")
local info = TweenInfo.new(0.1,Enum.EasingStyle.Sine,Enum.EasingDirection.Out)

local MouseDown = false

Mouse.Button2Down:Connect(function()
	if Character:FindFirstChildWhichIsA("Tool"):FindFirstChild("IsWeapon").Value == true then
		local Tool = Character:FindFirstChildWhichIsA("Tool")
		local Goal = {FieldOfView = 20}
		local TweenIn = TS:Create(Camera,info,Goal)
		TweenIn:Play()
		wait(0.1)
		Camera.FieldOfView = 20 ------Problem
	end
end)

Mouse.Button2Up:Connect(function()
	if Character:FindFirstChildWhichIsA("Tool"):FindFirstChild("IsWeapon").Value == true then
		local Tool = Character:FindFirstChildWhichIsA("Tool")
		local Goal = {FieldOfView = 70}
		local TweenOut = TS:Create(Camera,info,Goal)
		TweenOut:Play()
		wait(0.1)
		Camera.FieldOfView = 70
	end
end)

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