Selecting from a table and finding in an object? [Answered]
Asked by
5 years ago Edited 5 years ago
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.
01 | local craft = { "Log" , "Stick" , "Stick" } |
06 | for _,v in pairs (inv:GetChildren()) do |
07 | for _,slot in next , craft do |
08 | if v.Name = = slot then |
09 | table.insert(items, v) |
14 | if #items > = needed then |
18 | while took < needed do |
19 | for _,v in pairs (inv:GetChildren()) do |
20 | for _,slot in next , craft do |
21 | if v.Name = = slot and took < needed then |
Hey guys, future me here. I solved this problem by simply adding a table.remove() to the script and it fixed it all.