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

Get player name from onClicked function?

Asked by 8 years ago

So, I was wondering if it is possible to get the playername from a simple onClicked function such as:

function onClicked()

end

script.Parent.MouseButton1Down:connect(onClicked)

Any help would be appreciated.

1 answer

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

The MouseButton1Click event does not return the player that clicked. If you want to get the player then index LocalPlayer in game.Players.

--Define the player
local plr = game.Players.LocalPlayer

function onClicked()
    print(plr.Name)
end

script.Parent.MouseButton1Down:connect(onClicked)

NOTE: This will only work in a localscript.

Ad

Answer this question