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)

local event = game.ReplicatedStorage.TheyDiedLol

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        char:WaitForChild("Humanoid").Died:connect(function(killed)
            local killer = char.Humanoid:FindFirstChild("creator")
            if killer.Value then
                local killerName = killer.Value.Name
                event:FireAllClients(plr, killerName)
            end
        end)
    end)
end)
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)

game.ReplicatedStorage.TheyDiedLol.OnClientEvent:Connect(function(Player, plr, killer)
    local playerKiller = game:GetService("Players"):FindFirstChild(killer) --find the player using the killer name
    if playerKiller then --check if the player still exists or is still in the game or not
        local weapon = playerKiller.Character:FindFirstChildWhichIsA:("Tool") --finds a child of the killer's character and makes sure it's a tool
        if weapon ~= nil then --obviously checks if it still exists or not
            local weaponName = weapon:GetFullName() --gets the full name
            --now you have the weapon name, and maybe you could send it in as a weapon.
        end
    end
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.

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