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

Can I take the name of a player from the .Equipped function?

Asked by 5 years ago

Hello. I am trying to grab the name of a Player from the Equipped function so I can move a script over. Is this possible.

I have already tried,

script.Parent.Equipped:Connect(function(player)

print(player)

end)

However when equipping the tool it prints out 'instance' and not the name of the player.

Thank you for your contributions.

2 answers

Log in to vote
0
Answered by
Imperialy 149
5 years ago

you cannot grab the player inside the argument, but you can get the mouse through the args

script.Parent.Equipped:Connect(function(mouse)
    local character = script.Parent.Parent
    local player = game:GetService("Players"):GetPlayerFromCharacter(character)
    print(character.Name)
end)
0
you can only get the mouse if it is a localscript i believe, Imperialy 149 — 5y
Ad
Log in to vote
-1
Answered by 5 years ago
Edited 5 years ago

First of all, i believe the script should be inside the LocalScript.

local p = game.Players.LocalPlayer  
script.Parent.Equipped:Connect(function()
print(p.Name)
end)

So it would print out the player’s name, If you want it to be in a Server Script, use a RemoteEvent!

Here is an existing thread about it: https://scriptinghelpers.org/questions/53587/how-do-you-get-a-player-name-in-a-server-script

0
btw, u can use localscripts on tools since it is from ur backpack. NickAtNick 163 — 5y

Answer this question