Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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?

2 comments

0

Using a creator tag is the most popular, and the easiest, but I'm sure there are more complex ways to do it.

0

Is there anywhere where where I can find more information on these "Creator Tags"?

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.