Let's say a Player kills an NPC, and the NPC just has to print the name of the killer. How do I index the player that killed the NPC?
Thanks in advance.
Let's say a Player kills an NPC, and the NPC just has to print the name of the killer. How do I index the player that killed the NPC?
Thanks in advance.
Assuming the weapon inserts the creator tag in to the victims Humanoid.
local npc = script.Parent
local humanoid = npc:WaitForChild("Humanoid")
humanoid.Died:connect(function()
local tag = humanoid:findFirstChild("creator")
-- ObjectValue
if tag then
-- There was a killer. If the npc uses weapons, check to make sure it didn't kill itself with that.
print(tag.Value.Name)
else
-- There wasn't a killer.
print(npc.Name.. " jumped off a ledge or a tag was never created.")
end
--print (tag and tag.Value.Name or npc.Name.. " killed itself or no tag was created.")
end)
If you take apart a sword script, the player gets KOs the same way in which you are looking for.
This discussion is preserved as it was. New answers, comments, and votes are closed.