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

How do I figure out who killed who with a script?

Asked by
Discern 1007 Moderation Voter
10 years ago

So I have a gun script, and a main game script. When someone kills someone else with a gun script, I want the main game script to figure out who the killer was. How can I figure out who the killer is? Are there any built-in methods or events to help me figure out the killer?

0
Using a creator tag is the most popular, and the easiest, but I'm sure there are more complex ways to do it. Tkdriverx 514 — 10y
0
Is there anywhere where where I can find more information on these "Creator Tags"? Discern 1007 — 10y

1 answer

Log in to vote
1
Answered by 10 years ago

Heres a way

InsertTag script -- make sure its in a localscript inside a Tool

local Player = game.Players.LocalPlayer

function Died()
    local CT = Player.Character:FindFirstChild("Humanoid"):FindFirstChild("Creator_Tag")
    print(CT.Value .. " has killed " .. Player.Name)
end

function Hit()
    local Parent =  hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid") -- Where humanoid is located
    InsertTag(Parent)
end

function InsertTag(parent)
    local Creator_Tag = Instance.new("StringValue")
    Creator_Tag.Parent = parent
    Creator_Tag.Name = "Creator_Tag"
    Creator_Tag.Value = Player.Name
end

Bullet.Touched:connect(Hit)
Player.Character:FindFirstChild("Humanoid").Died:connect(Died)

This was not tested so it may not work.

Ad

Answer this question