I'm working on a script that gives items to the player when an enemy is killed. It also can give items at a chance such as having a 10% chance to get a legendary sword. Here's how I organize the loot table for my mobs.
local _C = {
DropsWeapon = {
true, {"Blizzard Striker", {1, 1}}, --Format is DoesItDropAnything?, {WeapoName, {Chances of dropping}}
{"Glaciersteel Cleaver", {3, 10}},
}
}
return _C
Here is the item drop script.
local MobConfig = require(script.Parent.MobConfig)
local Mob = script.Parent
local Enemy = Mob.Enemy
function DropItem()
if (Mob == nil) or (Enemy == nil) then return end
if (not Enemy:FindFirstChild("Player_Tag")) then return end
local Tag = Enemy:FindFirstChild("Player_Tag")
if (not Tag) and (not Tag.Value) then return end
local plr = Tag.Value
local BP = plr.Backpack
local SG = plr.StarterGear
for i, v in pairs(MobConfig.DropsWeapon) do
print("Loop Started")
if MobConfig.WeaponDirectory:FindFirstChild(MobConfig.DropsWeapon[i][1]) then
local DropChance = Random.new():NextInteger(MobConfig.DropsWeapon[i][2][1], MobConfig.DropsWeapon[i+1][2][2])
if MobConfig.DropsWeapon[i][2][1] == DropChance then
print("Drop Chance Check")
if SG then
if SG:FindFirstChild(MobConfig.DropsWeapon[i][1]) or BP:FindFirstChild(MobConfig.DropsWeapon[i+1][1]) then return end
local W1 = MobConfig.WeaponDirectory[MobConfig.DropsWeapon[i][1]]:Clone()
local W2 = MobConfig.WeaponDirectory[MobConfig.DropsWeapon[i][1]]:Clone()
W1.Parent = SG
W2.Parent = BP
print("Items Given")
end
end
end
end
end
if MobConfig.DropsWeapon[1] == true then
print("Checked for a drop")
Enemy.Died:Connect(DropItem)
end
The issue is whenever I use "i", the script errors with:
Attempt to index bool with number on line 15. Is it possible to skip over the first value in the droptable (true)?

3 comments
add an if statement stating to only do certain values, or even to skip certain ones. E.g: if v:IsA("NumberValue") then, or, if v.ClassName ~= "BoolValue" then
if (typeof(v) ~= "array") then continue end
Aight, I tried that, but it doesn't drop the item. At least it doesn't error. I'll try using print() to see where it doesn't work.