I see you have a array length check in the lowerright, I’m pretty sure a foreachloop will catch that, but if you really need to make sure the array has something (in the case of players will always have something, cannot remove the implant) you should have that check before you get to the array (Is array > than 0? If yes, Loop, if not break/do other logic)
Also I’m guessing somewhere in there you’re getting the item’s BaseCraftingMaterialRequirements and returning 1/2 of that (Is there a server config for return amount of something recycled? talking about demolishing structures) you might also have to multiply: BaseAmount * ((1+ItemRating) * ResourceRatingMultiplier)
I have ItemRating + 1 because I’m pretty sure items (crafted by player) start at rating 0.