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?
saveAs = "LS" dataStore = game:GetService("DataStoreService"):GetDataStore(saveAs) game.Players.PlayerRemoving:connect(function(player) player:WaitForDataReady() --To load stuff wait(1) --In case of crash and prevent being homeless stats = player["leaderstats"]:GetChildren() --Change "leaderstats" to your stats for i = 1, #stats do --Creates a loop for every stats dataStore:SetAsync(stats[i].Name, stats[i].Value .. player.userId) end end) game.Players.PlayerAdded:connect(function(player) player:WaitForDataReady() --To load stuff wait(1) --In case of crash and prevent being homeless stats = player["leaderstats"]:GetChildren() --Change "leaderstats" to your stats for i = 1, #stats do --Creates a loop for every stats stats[i].Value = dataStore:GetAsync(stats[i].Name .. player.userId) end end)
On line 10, your key looks like it's misplaced:
saveAs = "LS" dataStore = game:GetService("DataStoreService"):GetDataStore(saveAs) game.Players.PlayerRemoving:connect(function(player) player:WaitForDataReady() --To load stuff wait(1) --In case of crash and prevent being homeless stats = player["leaderstats"]:GetChildren() --Change "leaderstats" to your stats for i = 1, #stats do --Creates a loop for every stats dataStore:SetAsync(stats[i].Name .. player.userId, stats[i].Value) end end) game.Players.PlayerAdded:connect(function(player) player:WaitForDataReady() --To load stuff wait(1) --In case of crash and prevent being homeless stats = player["leaderstats"]:GetChildren() --Change "leaderstats" to your stats for i = 1, #stats do --Creates a loop for every stats stats[i].Value = dataStore:GetAsync(stats[i].Name .. player.userId) end end)
As for saving every 60 seconds, just set up a loop that runs and saves the data of every player every minute.
saveAs = "LS" dataStore = game:GetService("DataStoreService"):GetDataStore(saveAs) game.Players.PlayerAdded:connect(function(player) player:WaitForDataReady() --To load stuff wait(1) --In case of crash and prevent being homeless stats = player["leaderstats"]:GetChildren() --Change "leaderstats" to your stats for i = 1, #stats do --Creates a loop for every stats stats[i].Value = dataStore:GetAsync(stats[i].Name .. player.userId) end end) while wait(60) do for _, player in pairs(game.Players:GetChildren() do stats = player["leaderstats"]:GetChildren() --Change "leaderstats" to your stats for i = 1, #stats do --Creates a loop for every stats dataStore:SetAsync(stats[i].Name .. player.userId, stats[i].Value) end end end