DataStore not loading/saving leaderstats??
Asked by
Kulh 125
7 years ago Edited 7 years ago
Here's the code to load the stats:
01 | local DataStore = game:GetService( "DataStoreService" ):GetDataStore( "SurvivalsStorage" ) |
03 | game.Players.PlayerAdded:connect( function (player) |
05 | local stats = Instance.new( "IntValue" , player) |
06 | stats.Name = "leaderstats" |
07 | local Survivals = Instance.new( "IntValue" , stats) |
08 | Survivals.Name = "Survivals" |
10 | local Key = "user-" ..player.userId |
12 | local SaveWins = DataStore:GetAsync(Key) |
16 | Survivals.Value = SaveWins [ 1 ] |
18 | local ValuesToSave = { Survivals.Value } |
19 | DataStore:SetAsync(Key, ValuesToSave) |
24 | game.Workspace.ChildAdded:connect(Findthenoob) |
Here's the code that saves the stats:
01 | local DataStore = game:GetService( "DataStoreService" ):GetDataStore( "SurvivalsStorage" ) |
03 | game.Players.PlayerRemoving:connect( function (player) |
05 | local Key = "user-" ..player.userId |
07 | local ValuesToSave = { player.leaderstats.Survivals.Value } |
08 | DataStore:SetAsync(Key, ValuesToSave) |
Both are Server scripts in workspace
NOTE: I HAVE FILTERING ENABLED