Rescaling Scrolling Frame Accordingly With its Children Not Working

Hello and Thanks for Clicking on my Post.
I Know this Topic Has been Created Several Times on the Dev Forum But
Non of them Are Working Efficiently.

I Am Currently Trying to Make A Pet Inventory Type System
where the Inventory Scrolling Frame Scales accordingly to the Amount of Children in it.

I Tried Using A Script

local ScrollingFrame = script.Parent
local Layout = ScrollingFrame.Layout

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

ScrollingFrame.ChildAdded:Connect(function()
	ScrollingFrame.CanvasSize = UDim2.new(0, 0, 0, Layout.AbsoluteContentSize.Y)
end)

But this does not Work Properly.
I Use A Grid Layout In my Scrolling Frame and Each Element of the Scrolling Frame has A
UI Aspect Ratio Contraint.

Here is what Happens when i test

Thanks for Reading :happy1:

You have to change the CellSize as well.

When I work with UIGridLayouts, I like to set the cell’s size to be the same on the X axis as the Y axis.

So it usually would look something like this:

Layout.CellSize = UDim2.new(0.333,0,0,Layout.AbsoluteCellSize.Y)
-- note I put 0.333 because thats ~1/3

And that causes the grid to be compact, regardless of the amount of cells.

2 Likes

This is just inherent with using scale for cell size/padding with the grid layout object. It’s the reason I avoid it and I made my own grid layout script that does the sizing correctly and auto adjusts the scrolling frame as well. You can probably do something similar to decrease the scale in the Y direction as the scroll frame gets taller without having to code the grid part.

Works Amazing! Thank you So Much :happy3:

1 Like