Give player money when they kill someone

Hey, how would I give someone money when they kill someone? I want it so if they kill a player, they get 15$.

Networked Int is “Money”


function PlayerDeath( victim, weapon, killer )

if killer:IsPlayer() then 
killer:AddMoney(15)

end
end


or something like that.

Wow, I am an idiot. I made a timer to test if my save system worked, and I used v:AddMoney( 15 ), so I don’t know why I didn’t try killer:AddMoney( 15 ) for this function. Should work, thank you.

It doesn’t work :frowning:

Do you have Networked Int “AddMoney” too?

What do you mean Networked int “AddMoney”? I have the Networked Int, “Money”, and the function AddMoney…

Hmm, well the code Busymonkey posted should work then.
Are you calling it from the server or the client?

Server.

Hmm. Then im blank…
but you could try

[lua]
hook.Add( “PlayerDeath”, “GiveMoney”, function( victim, weapon, killer )
if killer:IsPlayer() then
killer:AddMoney(15)
end
end )
[/lua]

( Its the same thing Busymonkey posted, just in another way )
Im learing lua, so I dont really know what im doing all the time. :S

That did work, but even if I die it gives me 15$…

Thats because you’re the killer. You kill yourself.

[lua]
hook.Add( “PlayerDeath”, “GiveMoney”, function( victim, weapon, killer )
if killer:IsPlayer() and killer~=victim then
killer:AddMoney(15)
end
end )
[/lua]
Idk if that works, just give it a try.

Thank you Dragge. It worked, and it really helped. Thanks!

No problem :slight_smile: