I have a leaderboard script: `local dataStoreService = game:GetService("DataStoreService") --Service for DataStore
local cashDataStore = dataStoreService:GetDataStore("cashDataStore")--DataStore for Cash
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local cash = Instance.new("IntValue",leaderstats)
cash.Name = "Cash"
local data
local success,errormessage = pcall(function()
data = cashDataStore:GetAsync(player.UserId.."-Cash")
end)
if success then
cash.Value = data
else
print("There was an error while getting data")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success,errormessage = pcall(function()
cashDataStore:SetAsync(player.UserId.."-Cash",player.leaderstats.Cash.Value)
end)
if success then
print("Data successfully saved!")
else
print("There was an error when saving data!")
warn(errormessage)
end)` and i am trying to add 1+ value to cash after clicking a gui button.

6 comments
this isnt working for me i used your code by combining both parts and i used them in a script in a TextButton in starterGUI, yet it does nothing.(i did not move leaderboard script out of serverscript service.)
also i cant get the leaderboard to save, i used a auto save script by climaximus
Poor solution.
I'm sorry everyone; when I wrote this I forgot that the player object didn't have to be found again with a loop as that's inefficient. Also, I should've described how the RemoteEvents work further. Sorry about that.
I can make an answer if you'd like.
@spot6003 please help by making a answer.