I'm following a tutorial I found in the RBLX forums but for some reason I can't get the save to load? Can anyone show me what i'm doing wrong and and a method on how to correct it?
Also I was wondering what are some ways i can switch from the unreliable "Save on Remove" to a system that saves every 60 seconds?
01 | saveAs = "LS" |
02 |
03 | dataStore = game:GetService( "DataStoreService" ):GetDataStore(saveAs) |
04 |
05 | game.Players.PlayerRemoving:connect( function (player) |
06 | player:WaitForDataReady() --To load stuff |
07 | wait( 1 ) --In case of crash and prevent being homeless |
08 | stats = player [ "leaderstats" ] :GetChildren() --Change "leaderstats" to your stats |
09 | for i = 1 , #stats do --Creates a loop for every stats |
10 | dataStore:SetAsync(stats [ i ] .Name, stats [ i ] .Value .. player.userId) |
11 | end |
12 | end ) |
13 |
14 | game.Players.PlayerAdded:connect( function (player) |
15 | player:WaitForDataReady() --To load stuff |
On line 10, your key looks like it's misplaced:
01 | saveAs = "LS" |
02 |
03 | dataStore = game:GetService( "DataStoreService" ):GetDataStore(saveAs) |
04 |
05 | game.Players.PlayerRemoving:connect( function (player) |
06 | player:WaitForDataReady() --To load stuff |
07 | wait( 1 ) --In case of crash and prevent being homeless |
08 | stats = player [ "leaderstats" ] :GetChildren() --Change "leaderstats" to your stats |
09 | for i = 1 , #stats do --Creates a loop for every stats |
10 | dataStore:SetAsync(stats [ i ] .Name .. player.userId, stats [ i ] .Value) |
11 | end |
12 | end ) |
13 |
14 | game.Players.PlayerAdded:connect( function (player) |
15 | player:WaitForDataReady() --To load stuff |
As for saving every 60 seconds, just set up a loop that runs and saves the data of every player every minute.
01 | saveAs = "LS" |
02 |
03 | dataStore = game:GetService( "DataStoreService" ):GetDataStore(saveAs) |
04 |
05 | game.Players.PlayerAdded:connect( function (player) |
06 | player:WaitForDataReady() --To load stuff |
07 | wait( 1 ) --In case of crash and prevent being homeless |
08 | stats = player [ "leaderstats" ] :GetChildren() --Change "leaderstats" to your stats |
09 | for i = 1 , #stats do --Creates a loop for every stats |
10 | stats [ i ] .Value = dataStore:GetAsync(stats [ i ] .Name .. player.userId) |
11 | end |
12 | end ) |
13 |
14 | while wait( 60 ) do |
15 | for _, player in pairs (game.Players:GetChildren() do |