You can modify each resize function within the resizeFunctions table to ensure that the frame size does not exceed the defined maxWidth and maxHeight limits. This involves adding additional checks after calculating the newWidth and newHeight to ensure they don’t exceed the specified maximum values.
Here's the modified code with the additional maximum width and height checks included:
local resizeFunctions = {
TopLeft = function(delta)
local shiftPressed = UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) or UserInputService:IsKeyDown(Enum.KeyCode.RightShift)
local newWidth = math.max(startFrameSize.X.Offset - delta.X, minWidth)
local newHeight = shiftPressed and newWidth or math.max(startFrameSize.Y.Offset - delta.Y, minHeight)
newWidth = shiftPressed and newHeight or newWidth
-- Ensure newWidth and newHeight do not exceed maxWidth and maxHeight
newWidth = math.min(newWidth, maxWidth)
newHeight = math.min(newHeight, maxHeight)
frame.Size = UDim2.new(0, newWidth, 0, newHeight)
frame.Position = UDim2.new(0, startFramePos.X.Offset + (startFrameSize.X.Offset - newWidth), 0, startFramePos.Y.Offset + (startFrameSize.Y.Offset - newHeight))
end,
TopRight = function(delta)
local shiftPressed = UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) or UserInputService:IsKeyDown(Enum.KeyCode.RightShift)
local newWidth = math.max(startFrameSize.X.Offset + delta.X, minWidth)
local newHeight = shiftPressed and newWidth or math.max(startFrameSize.Y.Offset - delta.Y, minHeight)
newWidth = shiftPressed and newHeight or newWidth
newWidth = math.min(newWidth, maxWidth)
newHeight = math.min(newHeight, maxHeight)
frame.Size = UDim2.new(0, newWidth, 0, newHeight)
frame.Position = UDim2.new(startFramePos.X.Scale, startFramePos.X.Offset, 0, startFramePos.Y.Offset + (startFrameSize.Y.Offset - newHeight))
end,
BottomLeft = function(delta)
local shiftPressed = UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) or UserInputService:IsKeyDown(Enum.KeyCode.RightShift)
local newWidth = math.max(startFrameSize.X.Offset - delta.X, minWidth)
local newHeight = shiftPressed and newWidth or math.max(startFrameSize.Y.Offset + delta.Y, minHeight)
newWidth = shiftPressed and newHeight or newWidth
newWidth = math.min(newWidth, maxWidth)
newHeight = math.min(newHeight, maxHeight)
frame.Size = UDim2.new(0, newWidth, 0, newHeight)
frame.Position = UDim2.new(0, startFramePos.X.Offset + (startFrameSize.X.Offset - newWidth), startFramePos.Y.Scale, startFramePos.Y.Offset)
end,
BottomRight = function(delta)
local shiftPressed = UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) or UserInputService:IsKeyDown(Enum.KeyCode.RightShift)
local newWidth = math.max(startFrameSize.X.Offset + delta.X, minWidth)
local newHeight = shiftPressed and newWidth or math.max(startFrameSize.Y.Offset + delta.Y, minHeight)
newWidth = shiftPressed and newHeight or newWidth
newWidth = math.min(newWidth, maxWidth)
newHeight = math.min(newHeight, maxHeight)
frame.Size = UDim2.new(0, newWidth, 0, newHeight)
end,
Top = function(delta)
local shiftPressed = UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) or UserInputService:IsKeyDown(Enum.KeyCode.RightShift)
local newHeight = math.max(startFrameSize.Y.Offset - delta.Y, minHeight)
local newWidth = shiftPressed and newHeight or startFrameSize.X.Offset
newWidth = math.min(newWidth, maxWidth)
newHeight = math.min(newHeight, maxHeight)
frame.Size = UDim2.new(0, newWidth, 0, newHeight)
frame.Position = UDim2.new(startFramePos.X.Scale, startFramePos.X.Offset, 0, startFramePos.Y.Offset + (startFrameSize.Y.Offset - newHeight))
end,
Left = function(delta)
local shiftPressed = UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) or UserInputService:IsKeyDown(Enum.KeyCode.RightShift)
local newWidth = math.max(startFrameSize.X.Offset - delta.X, minWidth)
local newHeight = shiftPressed and newWidth or startFrameSize.Y.Offset
newWidth = math.min(newWidth, maxWidth)
newHeight = math.min(newHeight, maxHeight)
frame.Size = UDim2.new(0, newWidth, 0, newHeight)
frame.Position = UDim2.new(0, startFramePos.X.Offset + (startFrameSize.X.Offset - newWidth), startFramePos.Y.Scale, startFramePos.Y.Offset)
end,
Right = function(delta)
local shiftPressed = UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) or UserInputService:IsKeyDown(Enum.KeyCode.RightShift)
local newWidth = math.max(startFrameSize.X.Offset + delta.X, minWidth)
local newHeight = shiftPressed and newWidth or startFrameSize.Y.Offset
newWidth = math.min(newWidth, maxWidth)
newHeight = math.min(newHeight, maxHeight)
frame.Size = UDim2.new(0, newWidth, 0, newHeight)
end,
Bottom = function(delta)
local shiftPressed = UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) or UserInputService:IsKeyDown(Enum.KeyCode.RightShift)
local newHeight = math.max(startFrameSize.Y.Offset + delta.Y, minHeight)
local newWidth = shiftPressed and newHeight or startFrameSize.X.Offset
newWidth = math.min(newWidth, maxWidth)
newHeight = math.min(newHeight, maxHeight)
frame.Size = UDim2.new(0, newWidth, 0, newHeight)
end
}
Changes:
- Each resizing function now includes checks to ensure that
newWidth does not exceed maxWidth and that newHeight does not exceed maxHeight. After calculating newWidth and newHeight, math.min is used to ensure these values remain within that limit.
Make sure to define maxWidth and maxHeight appropriately before using these functions to obtain the desired behavior.