Hi, I got a problem with something. So I am trying to make it that when you buy something it refreshs the shop. In the shop script there is a i,v in pairs loop to delete all the previous frames from the shop but instead of deleting it, it multiples. I don’t know the problem to it. Can you please help me?
Module:
function module:LoadGUIStore(player)
local backpack = player.Backpack
local character = player.Character
local frames = script.Parent.Parent.Frames
local shopFrame = frames.Shop
local templateFolder = shopFrame.Templates
local toolSelection = shopFrame.ToolSelection
local ToolTemp = templateFolder["ToolTemplate"]
local extraFolder = ToolTemp["Extra"]
local ownedText = extraFolder["OwnedText"]
for i, v in pairs(toolSelection:GetChildren())do
if v:IsA("ImageButton") or v:IsA("TextButton")then
v:Destroy()
print("Removed "..v.Name)
end
for toolName, tool in pairs(itemInfo.Tools)do
if Tools:FindFirstChild(toolName) then
local Temp = ToolTemp:Clone()
local ToolNameTextLabel = Temp["ToolName"]
local ToolCostTextLabel = Temp["ToolCost"]
Temp.Name = toolName
ToolNameTextLabel.Text = toolName
ToolCostTextLabel.Text = tool["Cost"][1].." "..tool["Cost"][2]
Temp.Parent = toolSelection
Temp.LayoutOrder = tool["Cost"][1]
if backpack:FindFirstChild(toolName) and character:FindFirstChild(toolName)then
ownedText.Visible = true
else
ownedText.Visible = false
end
Temp.Visible = true
end
end
end
local deb = {}
for i, button in pairs(toolSelection:GetChildren())do
if button:IsA("ImageButton") or button:IsA("TextButton")then
button.Activated:Connect(function()
if deb[player.Name] == false or deb[player.Name] == nil then
deb[player.Name] = true
events["BuyTool"]:FireServer(button.Name)
wait(1)
deb[player.Name] = false
end
end)
end
end
end
Are you sure that the error is with this part of the script, and not the table that it is creating the buttons with? At first glance there should be no errors with what is given here.
TL;DR: Are you certain that itemInfo.Tools does not have duplicate entries?
“instead of deleting it, it multiples”
I think it deletes them but then it fills up all tools with the first tool’s data.
Probably you should test it by disabling the code from the 2nd for loop (“for toolName…”)
Some questions:
“if Tools:FindFirstChild(toolName) then” - where do you define Tools? Is it itemInfo.Tools?
“for toolName, tool in pairs(itemInfo.Tools) do” - is it correct? toolName will be a numeric counter in this way, as far as I know. Probably I missed this behavior of “for” loop, sorry in this case.
Tools = game.ReplicatedStorage[“Tools”], it is folder with all the tools in there. So that is checking if the selected tool is in the folder or not, if yes then continue on with the script.
I am pretty sure it gets the name of the table selected from the i,v in pairs loop. So what I am trying to say is that the for loop gets you the key and the value, which in this case, the key is the tool name and the value is the inside of the table which is why I do: