UiGridLayout Ignores Cloned Buttons

For ease of use, I’ve decided to make a LocalScript generate all the buttons I need in a Gui shop im working on. Each button is an exact clone of the first button, but the script makes all the necessary changes. Everything works fine, except for the UiGridLayout, which does not account for the clones that the script makes, so they all pile on top of each other. However, when I manually make duplicates of the button the layout works as intended.

Screenshot of the game running:

My Code:

local button = game.StarterGui.ShopGuis.PaintWalls.ScrollingFrame.ColorButton
local buttonsList = {
	Name = nil,
	Button = nil,
	Color = nil
}

local newTable = table.create(0, buttonsList)

for i = 1,10 do
	
	local listClone = table.clone(buttonsList)
	local newButton = button:Clone()
	
	newButton.Parent = button.Parent
	-- these are test values i'll implement once i get this working
	listClone.Name = "Button"
	listClone.Button = newButton
	listClone.Color = Color3.new(0, 0, 0)
	
	newButton.BackgroundColor3 = listClone.Color
	
	table.insert(newTable, listClone)
	
	wait()
end

do you mind sharing the properties of the ui grid layout? thanks

sure thing

I’m pretty sure it’s the FillDirectionMaxCells property, it should be more than 1.

tried 2 and 3. both don’t work sadly

That’s weird. I though that because all those buttons seem to be there, just in the same position.

last question then i know whats wrong, is this a server or local script and where is it located?

I just noticed that in the live preview, you’re showing game.StarterGui not [player].PlayerGui, do you mind showing it instead?

local button = script.Parent.ColorButton -- changed
local buttonsList = {
	Name = nil,
	Button = nil,
	Color = nil
}

local newTable = table.create(0, buttonsList)

for i = 1,10 do

	local listClone = table.clone(buttonsList)
	local newButton = button:Clone()

	newButton.Parent = button.Parent
	-- these are test values i'll implement once i get this working
	listClone.Name = "Button"
	listClone.Button = newButton
	listClone.Color = Color3.new(0, 0, 0)

	newButton.BackgroundColor3 = listClone.Color

	table.insert(newTable, listClone)

	wait()
end

just changed first line

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.