Rewarding Players For Killing NPC's?
So, recently I've been working on creating my own NPC's and all that stuff...well anyways, my question to whoever is willing to help is: How do I find the player who killed the NPC? How would I be able to do this, and find the exact player who killed the NPC so that I can award them? (I want the player to be awarded gold when the NPC is killed.)
Gold Stat: game.Players.Player.leaderstats.Gold
Heres what I have so far in the sword I made:
01 | Plr = game.Players.LocalPlayer |
11 | script.Parent.Parent.GripForward = Vector 3. new( 1 , 0 , 0 ) |
12 | script.Parent.Parent.GripPos = Vector 3. new( 0 , 0 ,- 1 ) |
13 | script.Parent.Parent.GripRight = Vector 3. new( 0 , 1 , 0 ) |
14 | script.Parent.Parent.GripUp = Vector 3. new( 0 , 0 , 0 ) |
16 | script.Parent.Parent.GripForward = Vector 3. new( 1 , 0 , 0 ) |
17 | script.Parent.Parent.GripPos = Vector 3. new( 0 , 0 ,- 1.5 ) |
18 | script.Parent.Parent.GripRight = Vector 3. new( 0 ,- 1 , 0 ) |
19 | script.Parent.Parent.GripUp = Vector 3. new( 0 , 0 , 1 ) |
25 | script.Parent.Touched:connect( function (Part) |
26 | if Part.Parent:FindFirstChild( "Humanoid" ) and Swinging = = true then |
29 | if not game.Players:FindFirstChild(PlrName) or game.Players:FindFirstChild(PlrName).Character~ = Plr then |
30 | Plr.Humanoid:TakeDamage(math.random( 5 , 8 )/ 2 ) |
35 | script.Parent.Parent.Equipped:connect( function () |
36 | Mouse.Button 1 Down:connect( function () |
37 | if Swinging = = false and ReadyToSwing = = true then |
If anyone could possibly help me, thank you in advance.
(If any more information is needed, please leave a comment.)