How to set a players leaderstats on Button1Down

Hi!
I’m trying to achieve a button that when clicked, sets the player clicked it’s leaderstats to 2. The problem is, I don’t know how to get the player from a button1click in a server script, if it’s even possible. If it isn’t possible, how else could I achieve this?

You need to add 2 to one of the Values in the leaderstats?

No, I need to set the value of leaderstats to 2.

Fire a RemoteEvent from the LocalScript and when it is fired you add a point on the server. Of course add a debounce on the server too.

3 Likes

For example, player.leaderstats.Cash.Value = 2 you want something like that?

How would I get the player from the button click in a remote event?

Yeah, as @vtaetwrjxvdpgwjqkfzw said, use a RemoteEvent because they are the one that connects the client with the server. As well, there are RemoteFunctions that works exactly like remote events but with a small difference, they return a value back to the client :slight_smile: .

local Button = script.Parent
Button.MouseButton1Down:Connect(function()
game.ReplicatedStorage.RemoteEvent:FireServer()
end)

How would I then get it from the server side and set the player’s leaderstat value after it’s fired?

Make sure to secure it in the server.

Read the Wiki post I linked. https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

It shows that the first parameter sent to the connection of a OnServerEvent signal is the player who called :FireServer at a given instant of time.