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

How to get owner of tool?

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

2 answers

✓ Accepted answer

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

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

2 comments

0

This doesn't work if the Tool is in the Player's backpack though.

0

true

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