Go to the very bottom to see the fix.
Hi there. So I have a pickup system to pick up objects from the world a put in in a player's custom inventory. I am also trying to create a crafting system to go along with this. I haven't written anything really for the system yet because I am stuck on this problem this the script. You see, the inventory is just a model that I set up. This is for testing before I really create one. And the inventory has 3 sticks and 2 logs. The script takes the 2 sticks but doesn't take any logs. This is where I got stuck
Server Script:
- By the way, inventory is referenced, it's just at the very top so I didn't copy it from the script.
local craft = {"Log", "Stick", "Stick"}
local items = {}
local needed = #craft
local took = 0
for _,v in pairs(inv:GetChildren()) do
for _,slot in next, craft do
if v.Name == slot then
table.insert(items, v)
end
end
end
if #items >= needed then
print("Enough")
spawn(function()
while took < needed do
for _,v in pairs(inv:GetChildren()) do
for _,slot in next, craft do
if v.Name == slot and took < needed then
v:Destroy()
took = took + 1
end
end
end
end
end)
end
Hey guys, future me here. I solved this problem by simply adding a table.remove() to the script and it fixed it all.

4 comments
So what's the question/problem?
The script takes the 2 sticks but doesn't take any logs.
^ thats the problem
Basically, the question is: how do I find 1 log in the model at the same time finding 2 sticks in a model and destroying them. And only 2 even if there's 20.