Here’s the setup I always use. Change the “Main” variable to your ScreenGui and you can also change the Padding and XCells variables. After it’s set up, just add all the frames you want to the ScrollingFrame and it’ll all be adjusted automatically. The CanvasSize of the ScrollingFrame is automatically adjusted to the exact length to fit all of your frames, so if you only have a few frames to display, it probably won’t have a scroll bar until you add enough to where it’s needed.
local player = game.Players.LocalPlayer
local Main = player.PlayerGui.Main -- Replace with the name of the ScreenGui (It'll be directly under StarterGui)
local ScrollingFrame = script.Parent.Parent
local UIGridLayout = script.Parent
UIGridLayout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function()
local absoluteSize = UIGridLayout.AbsoluteContentSize
ScrollingFrame.CanvasSize = UDim2.new(0, 0, 0, absoluteSize.Y)
end)
local function CalcCellSize()
local Padding = .05
local XCells = 3
local Size = (ScrollingFrame.AbsoluteCanvasSize.X*(1-Padding))/XCells
local PaddingSize = (ScrollingFrame.AbsoluteCanvasSize.X*Padding)/XCells
UIGridLayout.CellSize = UDim2.new(0, Size, 0, Size)
UIGridLayout.CellPadding = UDim2.new(0, PaddingSize, 0, PaddingSize)
end
repeat wait() until ScrollingFrame.AbsoluteCanvasSize ~= 0
CalcCellSize()
Main:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
CalcCellSize()
end)