Temporarily disable scroll to zoom

The title is self explanatory. How to I temporarily disable the camera zooming in and out via the scroll wheel?

There are two ways of doing that, you can set the min/max zoom to the current zoom, or use ContextActionService to bind a function that if returns Enum.ContextActionResult.Sink will prevent roblox from scrolling and if return Enum.ContextActionResult.Pass will allow roblox to zoom-in/out.


local ContextActionService = game:GetService("ContextActionService")
local DisableScroll = true

ContextActionService:BindAction("DisableScroll",
	function ()
		return DisableScroll and Enum.ContextActionResult.Sink or Enum.ContextActionResult.Pass
	end, false, Enum.UserInputType.MouseWheel)

Sorry for any typo, Im on phone lol

3 Likes

Here’s a “Hack” for the ones who are too lazy to code, Make a ScreenGui, Set ignoreGuiInset to true, add a ScrollingFrame and size it to {1,0},{1,0}, and then finally set the BackgroundTransparency and ScrollBarImageTransparency to 1.

This will prevent the player from scrolling but at the cost of moving your camera :frowning: . Maybe someone will find this useful idk.

local player = game:GetService("Players").LocalPlayer
local character=player.Character or player.CharacterAdded:Wait()
local humanoid=character:WaitForChild("Humanoid")
--ready to do whatever in a local script.

local zMin, zSet, zMax = 5, 5, 5 --lock it to 5
player.CameraMinZoomDistance = zSet
player.CameraMaxZoomDistance = zSet task.wait(0.1)
player.CameraMinZoomDistance = zMin -- 0.5 smallest call
player.CameraMaxZoomDistance = zMax

--or as a on the fly function
function Zoom(zMin, zSet, zMax)
	player.CameraMinZoomDistance = zSet
	player.CameraMaxZoomDistance = zSet task.wait(0.1)
	player.CameraMinZoomDistance = zMin
	player.CameraMaxZoomDistance = zMax
end

Zoom(0.5, 5, 16)

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