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

How to get owner of tool?

Asked by 9 years ago

How do I get the name of someone holding a tool?

2 answers

Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
9 years ago

In order to do this, we need to understand how tools work.


So, when a player has a tool with them that is unequipped it is located in the Players Backpack. When they have the tool equipped, it is inside there Character.

Knowing this, we can find the Player holding it, but we'll need the script to be able to distinguish it's potential parents from one another. Here's an example (The script is inside the tool) :

Tool=script.Parent

function CheckPlayer()
    local Player=nil
    if Tool.Parent.Name == "Backpack" then
        Player = Tool.Parent.Parent --Finds the Player using the Backpacks Parent.
    else
        Player = game.Players:FindFirstChild(Tool.Parent.Name) --Finds the Player using the Character's name, and searching through the Player's in game.
    end
    return Player
end

print(CheckPlayer()) --Prints the player's name.

Anyways, I hope this helped you out a bit :P

Ad
Log in to vote
0
Answered by 9 years ago

Tool.Parent.Name, Tool is a child of the Player's character in workspace, then you just get the Name of that character

0
This doesn't work if the Tool is in the Player's backpack though. dyler3 1510 — 9y
0
true dragonkeeper467 453 — 9y

Answer this question