Automatic CellSize scaling for UIGridLayout

I’m trying to automatically scale the CellSize of a UIGridLayout to stay within the boundaries of the frame but to also display the new rows and columns added. This is what I have so far:

Grid.FillDirectionMaxCells = Rows
	
Size = ((PlayingArea.AbsoluteSize.Y - 34) - (Columns - 1) * 10) / Columns
	
Grid.CellSize = UDim2.fromOffset(Size, Size)

This works for the columns, how could I apply this to the rows? (the CellSize should remain a square)

Edit: If it’s possible to also scale down the padding so that each tile will always be within the same distance, that would be nice

can you tell me what playingarea and grid are, and their respective sizes. just so i have an idea

Offsets
PlayingArea: 830x600
CellPadding: 10x10
CellSize: 105x105

PlayingArea is a Frame
Grid is a UIGridLayout

nevermind i dont think im right. i think i misunderstood your problem anyways


say there are n items in a grid. then there are n-1 paddings. we are working on the horizontal axis. lets also work in scale for ease. im also assuming the padding is not included at the end (p sure it isnt but i forgot).
(n-1)p + nx = 1, where x is the x size of the item. scale has no unit since its offset (pixels) divided by the viewportsize (pixels), so lets just call it scalards or something idfk. we know the sum of the paddings and each cells size is 1 scalard. we know n- it’s the number of columns. but do we know x, the size of each ui? i dont think there’s a way to separate the variables p and x (maybe im overisghting), but what you CAN do is vary the size of the X as the number of items increases. say 0.08 scalards to 0.07 to 0.06. then you can calculate the padding for items sized of that grid.

I think I understand but the UIGridLayout would have to be set in offset instead of scale

scale instead of offset*

scale’s better anyways. do you need the UI to be in offset? offset just keeps it a constant size in pixels. scale changes with the viewportsize, that is the window size of the game client.