Advertisement
EmeraldSlash

Drop Item Script (inside NPC)

Mar 1st, 2016
1,416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.70 KB | None | 0 0
  1. local dropChance = 20 -- out of 100, 0 being no chance, 100 being every time
  2. local npc = script.Parent
  3. local toDrop = script.ItemName -- what item the script gives npc's killer
  4. local human = npc.Humanoid
  5.  
  6. -------------------------------------------------------
  7.  
  8. function giveItem(p)
  9.     local chance = math.random(1,100)
  10.     if chance <= dropChance then
  11.         print("NPC died, dropped " ..toDrop.Name.. " which was picked up by " ..p.Name)
  12.         local c = toDrop:Clone()
  13.         c.Parent = p.StarterGear
  14.     else
  15.         print("NPC died, did not drop anything")
  16.     end
  17. end
  18.  
  19. human.Died:connect(function()
  20.     local tag = human:FindFirstChild("killer")
  21.     if tag then
  22.         local p = tag.Value
  23.         if p then
  24.             giveItem(p)
  25.         end
  26.     end
  27. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement