A loop is pretty inefficient for this kind of thing.
So, a Player's tools are stored in their backpack. So we can use the ChildAdded event. It looks like you're using a server script so I will attach the event to all players, but i'd recommend doing it on the client if you can.
game.Players.PlayerAdded:connect(function(Player)
Player.Backpack.ChildAdded:connect(function(Child)
for i,v in pairs(Player.Backpack:GetChildren()) do
if not v == Child and v.Name == Child.Name then
Child:Destroy()
end
end
end)
end)
When a player enters a game it attaches a ChildAdded event to their backpack. This event fires when a item gets put into the backpack, so a tool will trigger it. This triggers a loop that will check the names of each item in the Backpack and if the Child's name matches any tool then the Child is deleted.
3 comments
Oh my gosh! This is so helpful! Is there anyway to make it so they can one of Child but any further duplicates will be deleted?
Yeah, this is good
This should prevent duplicates from the start. When a tool is added to the Backpack, it checks all other tools against that tool. If a duplicate exists then the new tool is deleted so duplicates should never happen.