Loading...

UI Grid Layout | Forum

DoubleD606
DoubleD606 Oct 30 '25

9 Posts

i made a script that adds a layout to GUI automatically (like UIGridLayouts in modern roblox). It should just be a LocalScript parented to the container of the UI objects you want to be in a grid.

Script:

----|Grid Properties|----


--Note: all these properties are set to Scale instead of Offset meaning they need to be below 0


local xMoveBy = 0.15 --How much it will move each Gui components by on the xAxis

local xSpacing = 0.05 --Adds a gap between each item on the X Axis

local yMoveBy = 0.1 --How much it will move each Gui components by on the yAxis#

local ySpacing = 0.05 --Adds a gap between each item on the Y Axis

local maxX = 5 --How many Gui components can be on the xAxis

local maxY = 9 --How many Gui components can be on the YAxis


----|Main Script|----

xMoveBy = xMoveBy + xSpacing

yMoveBy = yMoveBy + ySpacing

local x = 0

local y = 0

local xCounter = 0

local yCounter = 0

local currentItem = 1

local items = {}

for i,v in pairs(script.Parent:GetChildren()) do

if v:IsA("GuiObject") then

table.insert(items,v)

end

end

repeat

wait()

repeat

local item = nil

for i,v in pairs(items) do

if i == currentItem then

item = v

end

end

print(item)

item.Position = UDim2.new(x,0,y,0)

x = x + xMoveBy

currentItem = currentItem + 1

xCounter = xCounter + 1

print(xCounter)

until xCounter >= maxX or currentItem == (#items + 1)

xCounter = 0

x = 0

yCounter = yCounter + 1

y = y + yMoveBy

until yCounter >= maxY or currentItem == (#items + 1)