I’m making a binocular gamepass with adjustable zoom from 1.5x to 3x. My issue is in the adjustable zoom part, the binoculars will zoom in and refuse to zoom out whether I have the binoculars turned on or not. I tried adding a debounce system, however, it helped me to no avail. Searching through Google/Devforum was no help either. Any help as to what I’m doing wrong and how I can fix it please?
local TS = game:GetService("TweenService")
local TI = TweenInfo.new(0.35, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)
game.ReplicatedStorage.AllowBinoculars.OnClientEvent:Connect(function()
local camera = workspace.CurrentCamera
local min = 1.5
local currentZoomLevel = 2
local max = 3
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local isZooming = false
game.UserInputService.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.B and not isZooming then
isZooming = true
script.Parent.Visible = true
local tween = TS:Create(camera, TI, {FieldOfView = camera.FieldOfView / currentZoomLevel})
tween:Play()
player.CameraMode = Enum.CameraMode.LockFirstPerson
local function WheelForward()
if camera.FieldOfView > camera.FieldOfView / max then
camera.FieldOfView = camera.FieldOfView / (currentZoomLevel + 0.05)
print(camera.FieldOfView)
end
end
local function WheelBackward()
if camera.FieldOfView < camera.FieldOfView / min then
camera.FieldOfView = camera.FieldOfView / (currentZoomLevel - 0.05)
print(camera.FieldOfView)
end
end
mouse.WheelForward:Connect(WheelForward)
mouse.WheelBackward:Connect(WheelBackward)
end
end)
game.UserInputService.InputEnded:Connect(function(input, gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.B and isZooming then
isZooming = false
script.Parent.Visible = false
local tween = TS:Create(camera, TI, {FieldOfView = camera.FieldOfView * 3})
tween:Play()
player.CameraMode = Enum.CameraMode.Classic
end
end)
end)