Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make the player not zoom out/in while scrolling on a ScrollingFrame on a SurfaceGUI?

So, whenever you scroll down or up in a Surface Gui using the scroll wheel, your camera zooms in or out.

Is there a way to prevent the player from zooming out or in, but when they are not scrolling, make them able to zoom in and out again? I'm pretty sure I can't use :Focused() on a scrolling frame.

2 comments

0

I'm not requesting a script, just asking how I could do this.

0

you could try locking the camera when the gui has focus, but this may become problematic.

1 answer

✓ Accepted answer

You could make a script that detects when the player's mouse is hovering over the frame, and then set the player's camera min and max zoom distance properties to whatever distance the camera is away from the head. That way the camera gets locked in place no matter what zoom level the player is at. Then when the player moves the mouse off the frame, the min and max zoom distance properties get reverted to whatever they were before. Something like this:

--This is basically pseudo-code that outlines essentially how you would do it
local prevMin = 0.5
local prevMax = 400
Frame.MouseEnter:connect(function()
	local camDist = (Cam.CoordinateFrame.p - Head.Position).magnitude
	prevMin = Player.CameraMinZoomDistance
	prevMax = Player.CameraMaxZoomDistance
	Player.CameraMinZoomDistance = camDist --Lock the zoom to whatever distance the camera is from the head
	Player.CameraMaxZoomDistance = camDist
end)

Frame.MouseLeave:connect(function()
	Player.CameraMinZoomDistance = prevMin --revert the zoom back to what it was before
	Player.CameraMaxZoomDistance = prevMax
end)

Hope this helped!

1 comment

0

It helped, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.