Position limits for a draggable gui

Hey! I’ve just created a draggable gui, by using this module. It works fine, however, I’d like to make some limitations for the drag. I want it to be able to drag to only some position values, basically I don’t want to make the player be able to drag it freely, wherever on the screen. (I’d like to make it look more like a “zooming” of a full-screen frame, instead of moving the frame across the screen.)

I made a script, which however doesn’t work. Does anyone know how I could achieve this?

The code:

local DraggableObject = require(script.Parent.DraggableObject)
local FrameDrag = DraggableObject.new(script.Parent)
local Frame = script.Parent
FrameDrag.DragStarted = function()
	if Frame.Position.Y.Scale > -0.001 and Frame.Position.Y.Scale < -0.584 and Frame.Position.X.Scale > -0.074 and Frame.Position.X.Scale < -0.874 then

Not too sure what you want, But you can use clamp to limit a number.

For example:
math.clamp(5, 1, 10)

This is going to print “5” because it didn’t go over the limit.

Another example:

math.clamp(17, 1, 10)

This is going to print 10 because it went over the limit

You can use clamp to limit the x or the y position of a frame.

I am not the best at English sorry.

1 Like