Scale ScrollingFrame on contents + Padding

When I try scaling the scrollingframe based on content size, it works well when there’s no padding, with pink being top, orange being bottom.


But now with a padding in the Y it doesn’t scale properly

So how can I fix this?

script.Parent.CanvasSize = UDim2.new(0, 0, 0, script.Parent.UIListLayout.AbsoluteContentSize.Y)

UI____Layout does consider padding in its AbsoluteContentSize; there is something else going on here. I suspect that somehow the CanvasSize is not being updated when you think it is.

Assuming each element’s size is correctly restricted, (probably with an AspectRatioConstraint) an easy way to get the CanvasSize to update approprietly is to make a connection like this:

UIListLayout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function()
     ScrollingFrame.CanvasSize = UDim2.new(0, 0, 0, UIListLayout.AbsoluteContentSize.Y)
     --don't forget to initially set the CanvasSize outside of this connection
end)