How would I save leaderstats?
I'll make this short, so I am trying to make a currency save system, but it won't work. So If I change "lvl" to 5, next time when I join the game it'll say "0", that means that I have no currency, obviously, no output errors as far as I can see.
01 | local players = game:GetService( "Players" ) |
02 | local datastore = game:GetService( "DataStoreService" ) |
03 | local ds 1 = datastore:GetDataStore( "CashValueSaver" ) |
05 | players.PlayerAdded:connect( function (player) |
06 | local folder = Instance.new( "Folder" ) |
07 | folder.Name = "leaderstats" |
08 | folder.Parent = player |
10 | local currency 1 = Instance.new( "IntValue" ) |
11 | currency 1. Name = "lvl" |
12 | currency 1. Parent = player.leaderstats |
13 | currency 1. Value = ds 1 :GetAsync(player.UserId) or 0 |
14 | ds 1 :SetAsync(player.UserId, currency 1. Value) |
16 | currency 1. Changed:connect( function () |
17 | ds 1 :SetAsync(player.UserId, currency 1. Value) |
Thanks!