How do I make this system better?

local mainFrame = script.Parent.Ui:WaitForChild("MainFrame")

local unitFrame = mainFrame.UnitFrame
local unitCategoryFrame = mainFrame.UnitCategoryFrame

local moduleFolder = game.ReplicatedStorage.Modules
local unitInfo = require(moduleFolder.UnitInfo)

for categoryKey, categoryData in pairs(unitInfo) do
	local createCategoryButtons = unitCategoryFrame.PlaceholderCategory:Clone()
	createCategoryButtons.Parent = unitCategoryFrame
	createCategoryButtons.Name = categoryKey
	createCategoryButtons.Image = categoryData.CategoryPicture

end
unitCategoryFrame.PlaceholderCategory:Destroy()

So I have a template button which will get cloned for how many categories there are in my module etc… etc…

Tho at the end I have to delete the template and keep the cloned ones that I can use.

Is this a good way to do it or is there a better fix?

You can parent the PlaceholderCategory to the script and set its visibility to false. Then, whenever you clone PlaceholderCategory, you can set the clone’s visibility to true.

You can also set the parent of PlaceholderCategory to nil. This will keep the placeholder in memory without deleting it.

1 Like

Do this but you can keep the visibility as true, if it’s in a script it won’t show anyways

1 Like