Problem with saving leaderstats

I’m currently trying to make a datastore that saves their money value, or in my game, ringgit. What I’ve done is used game.Players.PlayerRemoving function and then save it when it runs.
My script:

game.Players.PlayerRemoving:Connect(function(player)
    print(player.leaderstats.Ringgit.Value)
    local money = player.leaderstats.Ringgit.Value
    print(money)
        
    local datastore = game:GetService("DataStoreService"):GetDataStore("MAMoneyData")
    
    datastore:SetAsync(player.UserId, money)
end)

After that I used console to give myself money:
image

And when I left, this is what was printed:
image

Please let me know what I did wrong!

Are you modifying the money on the client?

I modified it using Roblox’s command bar on the bottom.

You executed the change on the client; changes made on the client do not replicate to the server.

If you’re running in the client, the command bar runs a local script, try switching to the server before run the command.

I tried it and turns out it work, thank you.

1 Like