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

Why does this give money on kill script not work on my zombie in workspace?

Asked by
Nozazxe 107
3 years ago
local Humanoid = script.Parent.Humanoid
function PwntX_X()
    local tag = Humanoid:findFirstChild("creator")
    if tag ~= nil then
        if tag.Value ~= nil then
            local Leaderstats = tag.Value:findFirstChild("leaderstats")
            if Leaderstats ~= nil then
                Leaderstats.Coins.Value = Leaderstats.Coins.Value + 10 --how much you get for killing the npc
                wait(0.1)
                script:remove()
            end
        end
    end
end
Humanoid.Died:connect(PwntX_X)

theres no error in output (atleast of what i saw). My leaderstats name is the same, so is coins.

1 answer

Log in to vote
1
Answered by
Gogulsky 129
3 years ago

If the humanoid has "creator" value in it - delete it. If the noob icon inside of the enemy is named Humanoid - this should work. Put this as a script inside of the enemy model.

local type = "Coins"

bot = script.Parent
human = bot.Humanoid

cash = 10



function onDied()
    local killer = human:findFirstChild("creator")
    if killer~=nil then
        local money = killer.Value.leaderstats:findFirstChild(type)
        if money~= nil then
            money.Value = money.Value + cash
        end
    end
end

script.Parent.Humanoid.Died:connect(onDied)
Ad

Answer this question