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

How do I get the name of the currently equipped weapon of a specific player?

Hello. So I'm currently trying to make an API that does a variety of things when a player kills another. I'm trying to add a line that will print out the name of a certain player's currently equipped tool.

So far I have this, I can't figure out how to find the name of the tool

local baddy = Humanoid.creator.Value
local Weapon = baddy:WaitForChild("Backpack")

Thank you all for the help.

2 answers

✓ Accepted answer

As soon as a player equips a weapon, it is moved to the player's Character. If we wanted to find a specific tool, we could do: baddy.Character:FindFirstChild("WeaponName")

However, if we wanted to find any tool that may be equipped in the player's inventory, we can use the :FindFirstChildOfClass("Tool") function since a tool is a Class.

local ToolEquipped = baddy:FindFirstChildOfClass("Tool")
print(ToolEquipped.Name)

This should work

Weapon:FindFirstChild("Your weapon name")

5 comments

0

Would this only work a for a local script inside the player?

0

no, this would work in a normal script and local, you have defined "Weapon" as the players backpack so you could put this script almost anywhere, I don't know what you are planning but I would put it in server script service because that is where most scripts go.

0

this gets the object, not the name and if the weapon specified doesnt exist it will error

0

if you don't want an error do, if Weapon:WaitForChild("Name") then --Do your script else end

0

Thank you, I was looking for a script to get a non specific weapon though

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