Hi there! I am trying to figure out how to get who killed a player. I remember seeing this on the Developer Hub a while ago, but cannot find it anymore. Here is my recreation of the code:
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:FindFirstChild("Humanoid")
humanoid.Died:Connect(function()
local tag = humanoid:FindFirstChild("creator")
print(tag.Value)
end)
end)
end)
The output keeps saying that I’m attempting to index nil with value. I cannot figure out why. Any help is appreciated!
2 Likes
You need to check if the tag value actually exists. if findFirstChild doesnt find what you need, then it returns nil.
do:
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:FindFirstChild("Humanoid")
humanoid.Died:Connect(function()
local tag = humanoid:FindFirstChild("creator")
if tag then
print(tag.Value)
end
end)
end)
end)
1 Like
Ah. So killing myself by resetting my character will not work.
You need to create a tag called “creator” and set the value to the player that killled you
You can make it so if the script doesnt find the creator tag, then you can do something like:
Player fell out of this world
and stuff like that
1 Like
Okay. That makes a LOT more sense. I think I’ll create my own tool! Thanks!
1 Like