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

How to get a weapon's name that a player was killed by?

Asked by 4 years ago
Edited 4 years ago

How do I get a weapon's name whenever someone died by that person's weapon they're holding.

(Replicated Storage)

01local event = game.ReplicatedStorage.TheyDiedLol
02 
03game.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)
13end)
0
I forgot to say that I didn't include the weapon code because I legit have no clue how to get the weapon's name from the person's character TheBuliderMC 84 — 4y
0
Forgot to also say so sorry for the person who answered first... All of this will display in the StarterGUI saying plr killed by plr using (WEAPON) TheBuliderMC 84 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

If it's a tool, what you could easily do is:

(for the local script assuming it is)

01game.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
10end)

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.

0
What I'm trying to do is that I want to try to get the weapon's name from the ReplicatedStorage and transfer it to StarterGui which displays the name of that weapon TheBuliderMC 84 — 4y
0
There is a weapon in ReplicatedStorage? Also, this is how you get the weapon's name and the weapon from the player's character who killed the player. xxIamInevitable 2 — 4y
Ad

Answer this question