I’ve been trying to make a obtain system where it checks if you have the obtainable already, so you won’t get duplicates, but for some reason, It keeps giving me duplicates, no errors show up, so what’s wrong with my script?
local deleteStuff = {}
for i,v in pairs(Player.Character:GetChildren())do
if v.ClassName == "Tool" then
table.insert(deleteStuff,v.Name)
end
end
for i,v in pairs(Player.Backpack:GetChildren())do
table.insert(deleteStuff,v.Name)
end
for i, v in pairs(GUI.Obtainables:GetChildren())do
print(v.Name)
for q, w in pairs(deleteStuff)do
if v.Name == w.Name then
v:Destroy()
print(w.Name)
end
end
end
local obtainablechildren = GUI.Obtainables:GetChildren()
local Chosen = obtainablechildren[math.random(#obtainablechildren)]
local Give = Chosen:Clone()
Give.Parent = GUI.Parent.Parent.Backpack