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

[Resolved] Tool existence check causes yielding in the script without error?

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 v ~= true then
View all 40 lines...

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.

1 answer

Log in to vote
0
Answered by
SWX253 2
4 years ago
Edited 4 years ago

The issue was I forgot to add a check for the existence of the player's Backpack on line 21. I should've went with:

1if SG and BP then

instead of

1if SG then

on line 21.

Ad

Answer this question