There are many tutorials on youtube on how to do this. I will link a video that should answer your question.
https://www.youtube.com/watch?v=zJEiaPvAgv8 - All you have to do is change the variable to the cash you want to give them! Hopefully this answers your question!
Try using a RemoteEvent and putting it in ReplicatedStorage. Here I’m already assuming you have the currency put in leaderstats.
In the LocalScript, you use: game.ReplicatedStorage.RemoteEvent:FireServer()
Make sure it’s under the right conditions, e.g. meaning that it only happens when the button is activated.
In a ServerScript, you can use something like:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
to get the code to execute when it is fired. Then you add to your currency on that server script, inside the block of code that was created.
Hope this helped!
You could use this code:
local amount = 500 -- put the amount of money you wan't the player to get
script.Parent.MouseButton1Click:Connect(function()
game.Players.LocalPlayer.leaderstats.money.Value = game.Players.LocalPlayer.leaderstats.money.Value + amount
end)
This is another easy way to do this. @GoodHugogamer
Honestly I recommend using script.Parent.Activated
vs script.Parent.MouseButton1Click
because Activated takes into account when mobile players are clicking. Because mobile devices don’t have mice, MouseButton1Click
doesn’t work 100% of the time, at least from my experience.
Using remote events for this type of stuff is not a very good idea because people can easily make autofarm scripts.
Create a RemoteEvent in RepliatedStorage.
Create a localscript in the button:
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.RemoteEvent:FireServer()
end
Create a normal script in ServerScriptService:
local statName = "Money" -- the stat name
local addValue = 1 -- how much that will be added to the stat when the button is clicked.
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr)
plr.leaderstats[statName].Value += addValue
end
Hope this helped you.
Without a remote event, the coins that you have will not be changed on the server, this means that you cannot do many things with it such as use it with datastore or read it on the server.
it will if it is scripted on a server script rather than a local script
it is not a good idea to use remote events to give money. it is better to code it on a server script in the button
put a server script in the button and put this in:
local debouncing = false
local delayy = 1 -- if you want a delay
local player = script.Parent.Parent.Parent.Parent --depending how it is organised in the explorer
script.Parent.MouseButtonOneClick:Connect(function()
if debouncing == false then
debouncing = true
player.leaderstats.money.Value = player.leaderstats.money.Value + 100
wait(delayy)
debouncing = false
end
end)