[Resolved] Tool existence check causes yielding in the script without error?
Asked by
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.
04 | true , { "Blizzard Striker" , { 1 , 1 } } , |
05 | { "Glaciersteel Cleaver" , { 3 , 10 } } , |
Here is the item drop script.
01 | local MobConfig = require(script.Parent.MobConfig) |
02 | local Mob = script.Parent |
03 | local Enemy = Mob.Enemy |
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 |
11 | local BP = plr.Backpack |
12 | local SG = plr.StarterGear |
13 | for i, v in pairs (MobConfig.DropsWeapon) do |
16 | if MobConfig.WeaponDirectory:FindFirstChild(MobConfig.DropsWeapon [ i ] [ 1 ] ) then |
17 | local DropChance = Random.new():NextInteger(MobConfig.DropsWeapon [ i ] [ 2 ] [ 1 ] , MobConfig.DropsWeapon [ i ] [ 2 ] [ 2 ] ) |
18 | if MobConfig.DropsWeapon [ i ] [ 2 ] [ 1 ] = = DropChance then |
19 | print ( "Drop Chance Check" ) |
20 | print (MobConfig.DropsWeapon [ i ] [ 1 ] ) |
22 | if not SG:FindFirstChild(MobConfig.DropsWeapon [ i ] [ 1 ] ) and not BP:FindFirstChild(MobConfig.DropsWeapon [ i ] [ 1 ] ) then |
24 | local W 1 = MobConfig.WeaponDirectory [ MobConfig.DropsWeapon [ i ] [ 1 ] ] :Clone() |
25 | local W 2 = MobConfig.WeaponDirectory [ MobConfig.DropsWeapon [ i ] [ 1 ] ] :Clone() |
37 | if MobConfig.DropsWeapon [ 1 ] = = true then |
38 | print ( "Checked for a drop" ) |
39 | Enemy.Died:Connect(DropItem) |
The issue is line 22 doesn't seem to check for the weapons' existence. There aren't any errors but I never see "Items Given" in the output.