There are a few issues with this code so I’ll walk you through them.
Firstly, the moustButton1Click is an input, and as such should be handled on the client. However, the players cash value should be handled on the server, as to stop exploiters giving themselves infinite amounts of cash. To fix this, you’ll have to use RemoteEvents. You can read through them there, but in short, we’ll be using the FireServer and OnServerEvent Events.
Now, let’s start writing your code.
local remote = REMOTE_EVENT_HERE
Next, MouseButton1Click is an event in GUIs, so I assume you’re using a UI. Let’s define that and then fix the Event.
local REMOTE = REMOTE_EVENT_HERE
local UI_BUTTON = BUTTON_HERE
UI_BUTTON.MouseButton1Click:Connect(function()
-- To be continued
end)
Now, we’re going to have to fire the server with the remote we referenced earlier. To do that, we’ll simply use the FireServer Method, as such:
local REMOTE = REMOTE_EVENT_HERE
local UI_BUTTON = BUTTON_HERE
UI_BUTTON.MouseButton1Click:Connect(function()
REMOTE:FireServer()
end)
With this, we now need to go to a normal script and write some code on the server. Once you do that, we’ll define the remote again and this time we’ll use the other event mentioned earlier, OnServerEvent. This event fires every time the client uses FireServer. The first parameter provided in this event is the player, and any arguments following that are ones sent via the client.
local REMOTE = REMOTE_HERE
REMOTE.OnServerEvent:Connect(function(PLAYER)
-- To be continued
end)
Now, we simply have to get the players leaderstats and increase the cash value. I’ll use the += operator as it looks better and is more efficient.
local REMOTE = REMOTE_HERE
REMOTE.OnServerEvent:Connect(function(PLAYER)
player.leaderstats:WaitForChild("Cash").Value += 1
end)
And after all of that, your code should hopefully work. All though this is inefficient, prone to exploiting and could cause lag, for what you want it’ll be fine.