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

Need help with Evercyan's rpg kit drop chance script?

Asked by 2 years ago

ok so i got this script to add drop chances to my enemies but whenever i kill the enemy i get this error:

 ServerScriptService.GameRemoteHandler.DamageEvent:38: attempt to index nil with 'Position'

and also

Workspace.Enemies.Deep Cave Golem (Lv. 1).MobDropScript:13: attempt to index nil with number

here is the script im using

local _M = 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
    local PICK = math.random(_M.DropChance[1],_M.DropChance[2])
    if _M.WeaponDirectory:FindFirstChild(_M.WeaponName) then
        if (PICK~=_M.DropChance[1]) then return end
        if SG then
            if (SG:FindFirstChild(_M.WeaponName)) then return end
            local W1 = _M.WeaponDirectory[_M.WeaponName]:Clone()
            W1.Parent = SG
        end
        if BP then
            if (BP:FindFirstChild(_M.WeaponName)) then return end
            local W2 = _M.WeaponDirectory[_M.WeaponName]:Clone()
            W2.Parent = BP
        end
    end
end

if _M.DropsWeapon == true then
    Enemy.Died:connect(DropItem)
end

Answer this question