ScrollFrame Canvas size to auto expand to fit all children

How would I go about to making a script that makes sure all contents of a scrollframe fit within the canvas size? I am using a UIListLayout to keep the order of scrollframes children.

You can put a frame with size (1,0,1,0) inside the scrollFrame, the content in the frame.
The scrollCanvas you can put with autoCanvas in XY, And canvasSize into (0,0,0.5,0)

You can get the UIListLayout.AbsoluteContentSize or you can use ScrollingFrame | Roblox Creator Documentation as @ancadejo10 said.

local ScrollingFrame = script.Parent

ScrollingFrame.CanvasSize = UDim2.new(0, ScrollingFrame.UIListLayout.AbsoluteContentSize.X, 0, ScrollingFrame.UIListLayout.AbsoluteContentSize.Y)

For unknown reasons this doesn’t seem to be working, no errors appear in the developer console.

Hi, I fixed the script now. Check if it works now.