Changing scrollframe size depending on items?

So I have a scroll frame and I want to script it so when there a certain amount of items the inventory will increase? I am new to scripting and not quite sure how to script that!

CurrentLayout:
image

ScrollFrame Properties:
image

UIAspectRatio Properties:
image

UIGridLayout Properties:

Item frame properties:

What I do is have a function that whenever the AbsoluteContentSize of the UIGridLayout changes, the scrolling bar adjusts to that change. It looks something like this

UIGridLayout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function()
     ScrollingFrame.CanvasSize = UDim2.new(0, 0, 0, UIGridLayout.AbsoluteContentSize.Y)
end)

This makes it that whenever an item is added to the scrolling frame, it changes the size of the scrolling frame to the match the size of the UIGridLayout’s Y axis.

2 Likes

Little trick I love doing. You can use

UDim2.fromOffset(0, UIGridLayout.AbsoluteContentSize.Y);

for less typing.

3 Likes

Hey sorry to revive this convo but does anyone have a solution to fixing the gapping issue that seems to appear when there’s a decent amount of frames?

1 Like