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!
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))