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 the name of a player who clicked a button?

I want to get the name of the player who clicked a button. Once I get their name I can add Coins to their stash. How do I do this? This is the code I have written so far. (I just need the name part) Thanks!

function onClicked()

game.Players.[I NEED NAME HERE].leaderstats.Coins.Value = game.Players.[I NEED NAME HERE].leaderstats.Coins.Value + 25

end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 answer

✓ Accepted answer

ClickDetectors have a built-in parameter for which player clicked the button. All you have to do is add it in.

function onClicked(player)

game.Players:FindFirstChild(player.Name).leaderstats.Coins.Value = game.Players:FindFirstChild(player.Name).leaderstats.Coins.Value + 25

end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

2 comments

0

Going indirectly through their .Name is silly. Just use player.leaderstats

0

I had that, but when I double checked on the wiki it was using so I worried it would be wrong.

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