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

Get player name from onClicked function?

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

✓ Accepted answer

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.

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