So I have a GUI backpack that works by putting parts into a pack model in the LocalPlayer when foraged. The backpack script then makes a button for each part in the pack when the Update() function below is called. The problem is that if there are already items in the pack (buttons present) when the Update() is called it puts the new buttons over the old ones as if they aren't there. How can I solve this? I've tried messing with the x and y positions but I don't know how to tell the script where the newest button is. Is there a way to count the number of buttons in the backpack frame and then make the starting x and y positions certain numbers based on how many buttons are in the backpack? Thanks for any help guys!
function Update() local player = game.Players.LocalPlayer local char = player.Character local pack = player:findFirstChild("Pack") local pack2 = player:findFirstChild("Pack2") local pack_tab = pack:GetChildren() local Ipack_tab = IFRAME:GetChildren() if CURRENT == nil then print ("current is nil") local x = 0 local y = 0 for index, child in pairs(pack_tab) do local CHOICE_GUI = MFRAME.TextButton:clone() CHOICE_GUI.Size = UDim2.new(0, 100, 0, 20) CHOICE_GUI.Transparency = .4 CHOICE_GUI.BackgroundColor3 = Color3.new() local new_gui = CHOICE_GUI CURRENT = new_gui new_gui.Position = UDim2.new(0, x, 0, y) new_gui.Text = child.Name new_gui.TextColor3 = Color3.new(255,255,255) new_gui.Name = child.Name new_gui.MouseButton1Down:connect(function() onGuiClick(child) end) new_gui.Parent = IFRAME new_gui.Visible = true local CHILD = pack:FindFirstChild(child.Name) CHILD.Parent = pack2 y = y + 20 if y > 240 then y = 0 x = x + 100 end end --cleanGui() end end