How to create gui boundaries?

Hi everyone! I recently created gui boundaries for my drawing system however, the y axis boundary is not working properly. Here is my code:

local module = {}

local function convertOffPosToScaleX(x, root)
	local totalX = root

	local finalX = x/totalX

	return finalX

local function convertOffPosToScaleY(y, root)

	local totalY = root

	local finaly = y/totalY

	return finaly

function module.checkBound(SquarePos, SquareSize, mouseX, mouseY)
	local xMin, xMax = SquarePos.X.Scale-(SquareSize.X.Scale)/2, SquarePos.X.Scale+(SquareSize.X.Scale)/2
	local yMin, yMax = SquarePos.Y.Scale-((SquareSize.Y.Scale)/2), SquarePos.Y.Scale+((SquareSize.Y.Scale)/2)
	local newMouseX = convertOffPosToScaleX(mouseX,script.Parent.Parent.DrawingFrame.AbsoluteSize.X)
	local newMouseY = convertOffPosToScaleX(mouseY,script.Parent.Parent.DrawingFrame.AbsoluteSize.Y)
	if newMouseX > xMin and newMouseX<xMax then
		if newMouseY > yMin and newMouseY<yMax then
			return true
return module

Btw, everything is in scale since that was how I orginally programmed the drawing system.

Try using clip descendants. You can read more here: GuiObject.ClipsDescendants

See the only issue is this happens when you move the mouse faster:

Yea, I get that, I will try your script in a minute just clip descendants might be a quicker fix as it will cut any gui element which leaves the square.

any luck? charsssssssssssssssssssssss

Make the red part overlay ontop of the drawing so you can’t see the drawing off of the borders if you are desperate. (Give it a higher ZIndex)

How would that work since the background is white.