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 a player holding a tool?

Asked by 8 years ago

My friend gave me this, and i put it in the tool script, but when i test it says player is a nil value

local Tool = script.Parent
local Player = game.Players:findFirstChild(Tool.Parent.Name)
0
The first thing that comes to my mind is: Why is the F not capitalized? FindFirstChild needs it to be capitalized. iamnoamesa 674 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

The script running should be a LocalScript.

If the script is a LocalScript, then we can ask for the LocalScript to find the LocalPlayer executing the script.

local PlayerHoldingTheTool = game.Players.LocalPlayer
local PlayerName = PlayerHoldingTheTool.Name

PlayerHoldingTheTool is the LocalPlayer himself. PlayerName is his name.

If this helped, accept the answer! Hope this helped!

Ad

Answer this question