How would I integrate a size limiter for a drag-to-resize frame

Hi everybody,

For a while now I have had this problem where studio crashes because of horrible scripting (but I’ve been too lazy to try and figure it out). Basically I have a frame that you can drag to resize, and a size limiter. But due to the size limiter being in another script and being scripted poorly, it crashes studio.

I really just want to integrate the size limiter into the resize script (as the title says) so studio doesn’t crash. I have tried a few things including adding a debounce to the size limiter, but that just broke everything. The scripts are below.

Drag to resize script


Size limiter script


So that is basically it. Any pointers on how to do this would be great, thank you!

Edit: why did nobody tell me math.clamp exists??


i really recommend you to recreate your entire script and learn about TweenService, but here is the solution to the size limiter script:

local cam = workspace.Camera
local viewportSize = cam.ViewportSize

local MinSizeX = 484 --378
local MinSizeY = 347--271

--local MaxSizeX = 968
--local MaxSizeY = 694

local function ScaleToOffsetX(x)

	x *= viewportSize.X

	return x

local function ScaleToOffsetY(y)

	y *= viewportSize.Y

	return y

local MaxSizeX = ScaleToOffsetX(1)
local MaxSizeY = ScaleToOffsetY(1)

local ObjectSize = script.Parent

	if ObjectSize.Size.X.Offset < MinSizeX then
		ObjectSize.Size =, MinSizeX, ObjectSize.Size.Y.Scale, ObjectSize.Size.Y.Offset)	
	if ObjectSize.Size.Y.Offset < MinSizeY then
		ObjectSize.Size =, ObjectSize.Size.X.Offset, ObjectSize.Size.Y.Scale, MinSizeY)
	if ObjectSize.Size.X.Offset > MaxSizeX then
		ObjectSize.Size =, MaxSizeX, ObjectSize.Size.Y.Scale, ObjectSize.Size.Y.Offset)	

	if ObjectSize.Size.Y.Offset > MaxSizeY then
		ObjectSize.Size =, ObjectSize.Size.X.Offset, ObjectSize.Size.Y.Scale, MaxSizeY)
1 Like

You can use math.clamp, which could also reduce the lines in your script by alot.


local minX = 1
local maxX = 10

local minY = 1
local maxY = 10

local size =,math.clamp(X,minX,maxX),0,math.clamp(Y,minY,maxY))

I haven’t used TweenService in ages! What would TweenService be good for?

I had no clue that existed. Thank you, kind stranger!

1 Like

i recommend you to search to understand, because it can make so much cool things, like go from 1 to 10 in how many seconds do you want and with the interpolation that you want

Oh, I do know that. I was wondering if you meant it had anything to do with the script. Thank you anyways!

too lazy

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