Hey, I'm making a game and I'm getting this bug that duplicates my items because it doesn't detect if there are 2 of this item from a table. I've tried many ways to figure out how to detect 2 objects in the backpack/character. This is my current script which is basic, but doesn't get the job done if plr.Backpack:FindFirstChild(valks[i][1]) or char:FindFirstChild(valks[i][1]) then else This detects if there is already the same item inside it, but it doesn't prevent from 2 items going in there, how would I make it figure out if 2 of the same objects are in the backpack/character
COMMUNITY QUESTION
How would I detect two of the same objects in the same parent?
1 answer
I would do it by using GetChildren() and then go through each child and compare the child.Name to the object you're checking and if you get a match, don't add the object.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Isn't that a bit expensively inefficient
Probably.
Probably. How about having an array with each entry being one of the possible objects in inventory with the value true or false? Then you can just compare to that value to see if it's already in inventory or not.