Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I prevent Guis from cloning the same Gui twice?

Asked by
NGC4637 602 Moderation Voter
4 years ago
Edited 4 years ago

So uh I have an inventory script and a backpack gui. Everything functions however in this link you will see a weird bug where all the items cloned twice. Does anyone know how to delete extra clones?

https://gyazo.com/22c8c5ba3b43124ef87678666f3f45cf

this is the backpack script:

01local player = game.Players.LocalPlayer
02local character = player.Character
03local items = {}
04local buttons = {}
05game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false) -- Makes the original backpack gui invisible
06 
07function search()
08    for i,v in pairs(game.Players.LocalPlayer.Backpack:GetChildren()) do -- Find all item in a specific location
09        if v:isA("Tool") then -- If the item found is a "Tool"
10            table.insert(items,v) -- We're going to put all the tools found in a table.
11        end
12    end
13end
14 
15function refresh()
View all 61 lines...
0
can you put the codes in a code block? Struggage 10 — 4y
0
btw the game is treating the extra clones the same way as the normal clones. for example if the normal clone dissapears the extra also dissapears NGC4637 602 — 4y

1 answer

Log in to vote
0
Answered by
pwx 1581 Moderation Voter
4 years ago

You should clear the current items table before adding more in. On each refresh you're adding more and more of the same tool into that table.

1for index,item in pairs(items) do
2    table.remove(items,index)
3end
4-- rest of your insert item code here
0
It worked, thx NGC4637 602 — 4y
Ad

Answer this question