I'm not requesting, but at least a push, How do I find if a Player killed another Player.
In most ROBLOX-created gear, there is a tag (ObjectValue) inserted in the humanoid of the local player that links to whoever kills them. This tag is referred to as the CreatorValue
, and tracks the player's Knockout statistics both in-game and on their website profile.
For example, if I were to swing a bat at your character, an ObjectValue by the name of CreatorValue woud be instanced in your Humanoid with its value set to my player. If my assault resulted in your death, I would be awarded a Knockout.
local debris = game:GetService('Debris') object.Touched:connect(function (hit) if pcall(function() return hit.Parent.Humanoid end) then -- line above local tag = Instance.new('ObjectValue', hit.Parent.Humanoid) tag.Value = game.Players.LocalPlayer tag.Name = 'CreatorValue' debris:AddItem(tag, 5) -- give it enough time (5) before removing it -- Could also take care of damages here end end
N.B: Not every tool is obliged to follow this tradition, but it would definitely be necessary if you wanted those kills to be reported back to the website (and for updating leaderboard statistics).
In the script you want to handle leaderstats, you will want to check for the CreatorValue
's Value
property when the local player dies (Died
event fires).
Note: Only the most recent CreatorValue (first value found), will be taking into consideration when scouting through the Humanoid.
local players = game:GetService('Players') players.PlayerAdded:connect(function (player) player.CharacterAdded:connect(function (character) local humanoid = character:WaitForChild('Humanoid') -- waits for humanoid after character and player are -- added humanoid.Died:connect(function () --Humanoid dies local list = humanoid:GetChildren() -- list of all children of humanoid for i = 1, #list do --iterate if list[i].Name == 'CreatorValue' then -- if value at iterator is CreatorValue local suspect = list[i].Value -- suspect is murderer -- do something end end end) end) end)