Why won't this code work / save?
This is supposed to be a DataStore script I did from a tutorial but it doesn't seem to work. Any idea what's wrong?
Here's part one of the script:
01 | local DataStore = game:GetService( "DataStoreService" ):GetDataStore( "LolWhyDa" ) |
04 | game.Players.PlayerAdded:connect( function (player) |
06 | local stats = Instance.new( "IntValue" , player) |
07 | stats.Name = "leaderstats" |
09 | local points = Instance.new( "IntValue" , stats) |
10 | points.Name = "Points" |
12 | local coins = Instance.new( "IntValue" , stats) |
15 | local key = "user-" ..player.userId |
17 | local savedValues = DataStore:GetAsync(key) |
21 | points.Value = savedValues.Value [ 1 ] |
22 | coins.Value = savedValues.Value [ 2 ] |
24 | local valuesToSave = { points.Value, coins.Value } |
25 | DataStore:SetAsync(key, valuesToSave) |
Part 2, located in a seperate script
01 | local DataStore = game:GetService( "DataStoreService" ):GetDataStore( "LolWhyDa" ) |
04 | game.Players.PlayerRemoving:connect( function (player) |
06 | local key = "user-" ..player.userId |
08 | local valuesToSave = { player.leaderstats.Points.Value, player.leaderstats.Coins.Value } |
09 | DataStore:SetAsync(key, valuesToSave) |
both scripts are in ServerScriptService.