Auto expanding scroll frame

Hi all I have this code here:

script.Parent.ChildAdded:Connect(function()

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

end)

This works fine if I want to do the auto expanding scroll frame with pixel size, but is there any way i can change it so that it will also work with screen size. If I change it to screen size now all the individual elements remain their size in comparison to the canvas size so they just end up getting bigger, is there any way to work out what their size should be.

If you know how many elements there will be then yes, let’s say each element takes up a UDim2 Y scale value of 0.4 and you have 10 of those elements, you’ll likely need a containing scrolling frame with a Y scale value at or slightly above 4.

UDim2.new(4, 0, 0, 0)