To expand on the question, I want to find if same weapons are in the backpack (eg. two guns) and destroy all but one of them. Example of destroying a weapon (but doesn't detect if there are two or more of the same weapons in the Backpack/Startergear):
if player.Backpack:FindFirstChild("M4A4") player.Backpack.M4A4:Destroy(); end
You first would need to get all of the children, then check for duplicates or store them in a list e.g.
local tmpTable = {} -- store items names for I,v in pairs(player.Backpack:GetChildren()) do -- loop through all items found if tmpTable [v.Name] ~= nil then -- checks if item exists in the list print("a duplicate has been found") -- found item e.g. a duplicate v:Destroy() -- deletes tool else tmpTable [v.Name] = "a" -- we don't need to use the value we are only using the key print("item added to list") end end
The code above is just an example, I have not tested this in studio.
Hope this helps.