I want to make an npc give cash to whoever it kills, but I don't know how to do this. I know the script for player killing a player, but what about an npc? Any thoughts?

game.Players.PlayerAdded:connect(function(p) p.CharacterAdded:connect(function(c) c.Humanoid.Died:connect(function() local cv = c.Humanoid:findFirstChild("creator") if cv then local k = cv.Value if k and k ~= p then k.leaderstats.Kills.Value = k.leaderstats.Kills.Value+1 end end end) end) end)

6 comments

0

pretty much the same

0

Since you already have a script that kills for killing a player, you just need to check if they done the killing blow then give them cash.

0

How would I do this, like check if the humanoid health is less then 0?

0

(Im not completely sure about this but )define the humanoid, then fire a function when Humanoid.Died, then (the bit im not sure about), find the person who damaged the NPC so its health went under 0. You could change the stats to stats.Value = stats.Value + 25 or whatever

0

Post your script for killing a player, I could probably modify it so it can handle both NPCs and players

0

game.Players.PlayerAdded:connect(function(p) p.CharacterAdded:connect(function(c) c.Humanoid.Died:connect(function() local cv = c.Humanoid:findFirstChild("creator") if cv then local k = cv.Value if k and k ~= p then k.leaderstats.Kills.Value = k.leaderstats.Kills.Value+1 end end end) end) end)