–all of this is in a module script if that can help)
The gui clones itself over and over but it wont delete itself when I open the shop
I have tried to find solutions but can’t seem to find good and matching ones
here’s the script:
local shopGUI = script.Parent:FindFirstChild(“ShopGui”)
local frame = shopGUI.Frame
local container = frame.ContainerFrame
local itemTemplate = script.Template
local Shop = {}
Shop.__index = Shop
local function clearContainer()
for _, child in ipairs(container:GetChildren()) do
if child:IsA(“TextButton”) then
child:Destroy() --Won’t destroy the gui
end
end
end
function Shop.new(shop: string)
clearContainer()
local list = if shop == “Food” then toolConfig else toolConfig
ipairs guarantees orders, pairs doesnt. but like @bytesleuth said, you shouldnt use them anymore, generalised iteration is the new thing (thanks for letting me know lmaooo i didnt even know)
if you dont know already, Instance:GetDescendants() returns a table
local shopGUI = script.Parent:FindFirstChild("ShopGui")
local frame = shopGUI.Frame
local container = frame.ContainerFrame
local itemTemplate = script.Template
local Shop = {}
Shop.__index = Shop
local function clearContainer()
for _, child in ipairs(container:GetChildren()) do
if child:IsA("TextButton") then
child:Destroy()
end
end
end
function Shop.new(shop: string)
clearContainer()
local list = (shop == "Food") and toolConfig or toolConfig
for _, item in ipairs(list) do
local newItem = itemTemplate:Clone()
newItem.Parent = container
newItem.Text = item.Name
end
end
function Shop:open()
shopGUI.Enabled = true
end
function Shop:close()
shopGUI.Enabled = false
clearContainer()
end
return Shop
I haven’t been on this forum for a while but I found the problem, I forgot where it was exactly but I think it was a misspell on a capital, thank you all for your time.