Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Datastore won't load ?

Asked by 9 years ago

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?

01saveAs = "LS"
02 
03dataStore = game:GetService("DataStoreService"):GetDataStore(saveAs)
04 
05game.Players.PlayerRemoving:connect(function(player)
06player:WaitForDataReady() --To load stuff
07wait(1) --In case of crash and prevent being homeless
08stats = player["leaderstats"]:GetChildren() --Change "leaderstats" to your stats
09for i = 1, #stats do --Creates a loop for every stats
10dataStore:SetAsync(stats[i].Name, stats[i].Value .. player.userId)
11end
12end)
13 
14game.Players.PlayerAdded:connect(function(player)
15player:WaitForDataReady() --To load stuff
View all 21 lines...

1 answer

Log in to vote
0
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
9 years ago

On line 10, your key looks like it's misplaced:

01saveAs = "LS"
02 
03dataStore = game:GetService("DataStoreService"):GetDataStore(saveAs)
04 
05game.Players.PlayerRemoving:connect(function(player)
06player:WaitForDataReady() --To load stuff
07wait(1) --In case of crash and prevent being homeless
08stats = player["leaderstats"]:GetChildren() --Change "leaderstats" to your stats
09for i = 1, #stats do --Creates a loop for every stats
10dataStore:SetAsync(stats[i].Name .. player.userId, stats[i].Value)
11end
12end)
13 
14game.Players.PlayerAdded:connect(function(player)
15player:WaitForDataReady() --To load stuff
View all 21 lines...

As for saving every 60 seconds, just set up a loop that runs and saves the data of every player every minute.

01saveAs = "LS"
02 
03dataStore = game:GetService("DataStoreService"):GetDataStore(saveAs)
04 
05game.Players.PlayerAdded:connect(function(player)
06player:WaitForDataReady() --To load stuff
07wait(1) --In case of crash and prevent being homeless
08stats = player["leaderstats"]:GetChildren() --Change "leaderstats" to your stats
09for i = 1, #stats do --Creates a loop for every stats
10stats[i].Value = dataStore:GetAsync(stats[i].Name .. player.userId)
11end
12end)
13 
14while wait(60) do
15    for _, player in pairs(game.Players:GetChildren() do
View all 21 lines...
0
Ohhhhhh I see what I did wrong. Thank you for your help sir. PsychonautX 15 — 9y
0
No problem. Pyrondon 2089 — 9y
Ad

Answer this question