Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[Resolved] How To Skip Over A Value In An Array Within A For I, V Loop?

Asked by
SWX253 2
4 years ago
Edited 4 years ago

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.

01local _C = {
02 
03DropsWeapon = {
04        true, {"Blizzard Striker", {1, 1}}, --Format is DoesItDropAnything?, {WeapoName, {Chances of dropping}}
05        {"Glaciersteel Cleaver", {3, 10}},
06 
07    }
08 
09}
10 
11return _C

Here is the item drop script.

01local MobConfig = require(script.Parent.MobConfig)
02local Mob = script.Parent
03local Enemy = Mob.Enemy
04 
05function DropItem()
06    if (Mob == nil) or (Enemy == nil) then return end
07    if (not Enemy:FindFirstChild("Player_Tag")) then return end
08    local Tag = Enemy:FindFirstChild("Player_Tag")
09    if (not Tag) and (not Tag.Value) then return end
10    local plr = Tag.Value
11    local BP = plr.Backpack
12    local SG = plr.StarterGear
13    for i, v in pairs(MobConfig.DropsWeapon) do
14        print("Loop Started")
15        if MobConfig.WeaponDirectory:FindFirstChild(MobConfig.DropsWeapon[i][1]) then
View all 35 lines...

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)?

0
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 WizyTheNinja 834 — 4y
0
if (typeof(v) ~= "array") then continue end Ziffixture 6913 — 4y
0
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. SWX253 2 — 4y

Answer this question