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.
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
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