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

How can I get the player holding a tool?

Asked by 6 years ago

If this is obvious, don't laugh at me, because I haven't learned the function/keyword/statement/method/whatever yet, obviously.

How do I tell which player is holding a tool?

2 answers

Log in to vote
0
Answered by 6 years ago
local Tool = script.Parent

Tool.Equipped:connect(function()
local Character = Tool.Parent
local Player = game.Players:GetPlayerFromCharacter(Character) -- Returns the player's object
print(Player)
end)

Tested and works.

0
It does work! Thanks for your help! Fireorius 51 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

The easiest way is to check all the players characters and using "FindFirstChild". If it's in a server script, you'd want to do

for _,character in pairs(workspace:GetChildren()) do
    if character:FindFirstChild("ToolName") then
        print('Found Tool') -- and place whatever you want here
    end
end

There are other methods, but this is the first that comes to mind. Hope that helps!

Answer this question