How to maintain consistent sizing and padding with UIGrid (via code)

I’m trying to use code to set the CellSize of a GridLayout so sizes are evenly sized based on devices, and its a lot easier to work with offset over scale when trying to maintain an even padding around edges. This is my current code

local Frame = script.Parent

local Item = script:WaitForChild('Item')

local GridLayout = Frame:WaitForChild('UIGridLayout')

local xSize, ySize = Frame.AbsoluteSize.X, Frame.AbsoluteSize.Y

local Padding = GridLayout.CellPadding.X.Offset

local Cells = 9

local TotalPadding = Padding * (Cells - 1)

local CellSize = (xSize - TotalPadding) / Cells

GridLayout.CellSize =, CellSize, 0, CellSize)

for i = 1, Cells * 3 do
	local NewItem = Item:Clone()
	NewItem.Parent = Frame

And that produces this

However the padding between the left and right is not the same as the padding between top and bottom. I tried using UIPadding but I couldn’t figure out the math to get it even