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

How would I detect two of the same objects in the same parent?

Asked by 5 years ago

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

1 answer

Log in to vote
0
Answered by 5 years ago

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.

0
Isn't that a bit expensively inefficient Sapppower 17 — 5y
0
Probably. TerminusEstKuldin 40 — 5y
0
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. TerminusEstKuldin 40 — 5y
Ad

Answer this question