How do I get a weapon's name whenever someone died by that person's weapon they're holding.
(Replicated Storage)
01 | local event = game.ReplicatedStorage.TheyDiedLol |
02 |
03 | game.Players.PlayerAdded:Connect( function (plr) |
04 | plr.CharacterAdded:Connect( function (char) |
05 | char:WaitForChild( "Humanoid" ).Died:connect( function (killed) |
06 | local killer = char.Humanoid:FindFirstChild( "creator" ) |
07 | if killer.Value then |
08 | local killerName = killer.Value.Name |
09 | event:FireAllClients(plr, killerName) |
10 | end |
11 | end ) |
12 | end ) |
13 | end ) |
If it's a tool, what you could easily do is:
(for the local script assuming it is)
01 | game.ReplicatedStorage.TheyDiedLol.OnClientEvent:Connect( function (Player, plr, killer) |
02 | local playerKiller = game:GetService( "Players" ):FindFirstChild(killer) --find the player using the killer name |
03 | if playerKiller then --check if the player still exists or is still in the game or not |
04 | local weapon = playerKiller.Character:FindFirstChildWhichIsA:( "Tool" ) --finds a child of the killer's character and makes sure it's a tool |
05 | if weapon ~ = nil then --obviously checks if it still exists or not |
06 | local weaponName = weapon:GetFullName() --gets the full name |
07 | --now you have the weapon name, and maybe you could send it in as a weapon. |
08 | end |
09 | end |
10 | end ) |
If you don't know already, tools only appear in the player's character only if they have it equipped. But if they don't have it equipped then it will only remain in their backpack. With that being said, if it's a tool (which I hope it is) then you can get the tool's name using this method, which will fire as soon as possible when the specified player's (not the killer) humanoid dies. You can then proceed to set this into a value.