Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I index the killer? [closed]

Asked by
OniiCh_n 410 Moderation Voter
9 years ago

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.

Locked by OniiCh_n, Shawnyg, TofuBytes, and adark

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
2
Answered by
Azarth 3141 Moderation Voter Community Moderator
9 years ago

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)
Ad
Log in to vote
-3
Answered by 9 years ago

If you take apart a sword script, the player gets KOs the same way in which you are looking for.