First person zoom script not working properly

Hello I wanted to make a zoom script with the mouse wheel so every time you use the mouse wheel it could zoom in or out but it doesn’t seem to be working, I tried printing stuff as you can see, zoom script is running does print and so does handlezoom function but the rest doesn’t and the zoom does not work, why is that? any help is appreciated

local character = game.Players.LocalPlayer.Character
local camera = game.Workspace.CurrentCamera
local startingFOV = 45
local zoomedFOV = 30

camera.FieldOfView = startingFOV

local function handleZoom(inputObject)
	print("handleZoom function called")
	if inputObject.UserInputType == Enum.UserInputType.MouseWheel then
		local currentFOV = camera.FieldOfView
		local newFOV

		if inputObject.Position.Z > 0 then
			newFOV = math.max(startingFOV - 10, currentFOV - 5)
		else
			newFOV = math.min(startingFOV + 10, currentFOV + 5)
		end

		print("Current FOV:", currentFOV)
		print("New FOV:", newFOV)

		local FOVTweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
		local FOVTween = game:GetService("TweenService"):Create(camera, FOVTweenInfo, {FieldOfView = newFOV})
		FOVTween:Play()
		FOVTween.Completed:Connect(function()
			print("FOV tween completed")
		end)
	end
end

game:GetService("UserInputService").InputBegan:Connect(handleZoom)```

I haven’t messed around with mouse inputs in awhile however i dont think the way to properly detect the mouse is under “UserInputType”

This isn’t needed

1 Like

No problem, I found the solution to it yesterday, thank you for your help!

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