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

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

Asked by 4 years ago

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

Log in to vote
0
Answered by
lolzmac 207 Moderation Voter
4 years ago

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)
Ad
Log in to vote
0
Answered by
zomspi 541 Moderation Voter
4 years ago

This should work

Weapon:FindFirstChild("Your weapon name")
0
Would this only work a for a local script inside the player? jensar141215 157 — 4y
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. zomspi 541 — 4y
0
this gets the object, not the name and if the weapon specified doesnt exist it will error Warfaresh0t 414 — 4y
0
if you don't want an error do, if Weapon:WaitForChild("Name") then --Do your script else end zomspi 541 — 4y
0
Thank you, I was looking for a script to get a non specific weapon though jensar141215 157 — 4y

Answer this question