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

Script Not Functioning Right! Npc OnDeath Summons Item?

Asked by 4 years ago
Edited 4 years ago

how would i create a npc that when it dies, summons an items that spawns on them? been trying to script this for a while now, here is my current script:

while true do
    wait()
    if script.Parent.Humanoid.Health == "0" then
        Mod = game.ServerStorage.Lvl1Reward
        clone = Mod:clone()
        clone.Parent = workspace
        clone.Position = CFrame.new(script.Parent.Head)
        clone:MakeJoints()
        script.Parent:Destroy()
    end
end

The Script Doesnt Seem To Work, as it wont summon the item on the npc when it dies. If any of you guys know how to fix this, PLEASE HELP ME!

1 answer

Log in to vote
0
Answered by
pingsock 111
4 years ago
Edited 4 years ago
function RewardItem(Level)
    local npc = script.Parent
    if Level == 1 then
        local mod = game.ServerStorage["Lvl1Reward"]:Clone()
        mod.Parent = workspace
        mod.Position = script.Parent.Head.Position
        mod:MakeJoints()
        print('Success, destroying...')
        npc:Destroy()
    elseif Level == 2 then
        local mod2 = game.ServerStorage["Lvl2Reward"]:Clone()
        mod2.Parent = workspace
        mod2.Position = script.Parent.Head.Position
        mod2:MakeJoints()
        print('Success, destroying...')
        npc:Destroy()
    end
end

-- If you're using DataStores, you can put whatever level the player is for userlevel.
UserLevel = nil -- replace nil with whatever, because I haven't seen your game and dont know what to put.
script.Parent.Humanoid.Died:Connect(RewardItem(UserLevel))
0
okay, its amazing, however the script for 1. Doesnt need the if Level statements, its an npc that repspawns on death as well as the same thing. 2. for some reason the thing wont clone TheEmeraIdDev 22 — 4y
Ad

Answer this question