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!
1 | function onClicked() |
2 |
3 | game.Players. [ I NEED NAME HERE ] .leaderstats.Coins.Value = game.Players. [ I NEED NAME HERE ] .leaderstats.Coins.Value + 25 |
4 |
5 | end |
6 | script.Parent.ClickDetector.MouseClick:connect(onClicked) |
ClickDetectors have a built-in parameter for which player clicked the button. All you have to do is add it in.
1 | function onClicked(player) |
2 |
3 | game.Players:FindFirstChild(player.Name).leaderstats.Coins.Value = game.Players:FindFirstChild(player.Name).leaderstats.Coins.Value + 25 |
4 |
5 | end |
6 | script.Parent.ClickDetector.MouseClick:connect(onClicked) |