I've been making loot drops and I received the following error: Wrong number of arguments to 'insert'
ServerScript:
function getItem(ID) local items = game:GetService("ServerStorage").Items:GetDescendants() for i, v in pairs(items) do if v:FindFirstChild("ItemID") then if v.ItemID.Value == ID then return v end end end end function dropItems(mob) local loot = {} for i, v in pairs(mob.MobConfig.ItemsDropped:GetChildren()) do local probability = math.random(1, 100) if v.Value >= probability then table.insert(loot, getItem(v.Name)) --Error occurs here end end return loot end
Is there something trivial that I messed up on? Does table.insert need an index? Any help would be appreciated.
As I've already answered the question in the comments, for anyone else receiving the same error (Wrong number of arguments to 'insert')
While passing a nil variable is allowed, passing a nullary function is not. Make sure your function does not return nil or just use a variable for the second argument of table.insert