I'm trying to give a player xP when they earn a kill.
✓ ANSWER ACCEPTED
Event for doing something when a player kills someone?
1 answer
✓ Accepted answer
When a player kills another player with a weapon that correctly inserts the tag value, you can track who killed who. What is a tag value? That's just what I call it, because to me, it explains exactly what it does, it tags the player so the script can do something with it. This value is called an ObjectValue, an ObjectValue's Value leads back to an Instance, the killer in this case.
When a player kills another player with a ROBLOX linked sword, the victim will receive a 'tag' in their humanoid named 'creator', you can then configure a script to detect when a person dies and check for that tag. For instance;
local function player_died(player_who_died)
local humanoid = player_who_died.Character["Humanoid"]
local tag = humanoid:findFirstChild("creator")
if tag then
print("You were murdered!")
if tag.Value.Name == player_who_died.Name then
print("You killed yourself!")
else
print(tag.Value.Name.. " murdered you!")
end
else
print("You reset or the weapon you're using doesn't create the tag.")
end
end
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(c)
-- Note if you have turned off auto load, you will need a check before this event as well.
local hum = c:WaitForChild("Humanoid")
hum.Died:connect(function()
player_died(player)
end)
end)
end)
1 comment
0
That makes so much more sense, thanks man.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Basically, you need a script in the player who died that uses an ObjectValue to link back to the player who killed him, and from there do whatever is needed to the killer.