To change the stats from the client to the server you need a remote event, the event also has a parameter for the player going to and from the server.
Local Script
local remote = game:GetService("ReplicatedStorage"):WaitForChild("CollectMoney")
workspace.Part.SurfaceGui.TextButton.Activated:Connect(function()
remote:FireServer()
end)
Server Script
local remote = Instance.new("RemoteEvent")
remote.Name = "CollectMoney"
remote.Parent = game:GetService("ReplicatedStorage")
remote.OnServerEvent:Connect(function(player)
local stat = player:WaitForChild("leaderstats"):WaitForChild("CashValueNameHere")
stat.Value = stat.Value + 100
end)
The idea is you create a RemoteEvent which can then allow the Server and Client to communicate. When the button is clicked, the remote will tell the server to change the money / point system value of the player.
For the above example, the surface gui would be under a part named "Part" in the workspace with a TextButton under the gui.
Everytime the button is clicked, the player would gain 100 of the applicable stat, where the stat would be found under a folder / model in the player named "leaderstats"
3 comments
Just a few questions. Where in the localscript is it sending some sort of player ID to the server?, Do I have to create the remote event beforehand due to the client sending it to nothing otherwise? And if so, why is it being created again in the server script? Lastly, how can I get the localscript to change the amount of cash that has been collected back to 0? So all other players can see it has
Remote Events from the client to the server tell the server who fired it, it sends the actual player instance, not their id. You can create the remote beforehand, but the server script here will do that for you. It needs to be created on the server so that there is a copy of the remote event on the server and not just the client (the same replicated storage is used by both entities).
Any changes to the player's cash value on the server will be replicated for all clients to see, any changes on the client will only be visible to the client. In order to revise the cash collect to zero, i'd have to look at the script you are using for that. Also based on what you said in another comment, you can use the :GetDescendants() method of the workspace and check that the item is a textbut