The best way of doing this is to use remote events:
Make sure you insert a remoteevent into replicatedStorage.
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new('Folder')
leaderstats.Name = 'leaderstats'
leaderstats.Parent = player
local coins = Instance.new('IntValue')
coins.Name = 'Coins'
coins.Parent = leaderstats
end)
This script is what I used to create the currency Coins (your currency can be any name)
When you have created your GUI, insert a local script into the textbutton.
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.RemoteEvent:FireServer()
end)
This will fire the remote event
Now insert a script into the workspace and type the following:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
end)
This will make it every time you click the button your currency will increase by 1.
2 comments
That change will not replicate to the server. Do it through RemoteEvents.
How do I do that? Ive never used remote events.