You’re going to need to manually hardcode the key names into your script. If you reuse the key names from the then-current datastore, the format may have been changed (key removed or added). Then you just do
function loadAll16Keys()
local oldData = {}
local oldKeyNames = { "totalTimePlayed", "Credits", ... }
local oldDataStore = datastoreservice:GetDataStore(oldDataStoreName)
for _,keyName in pairs(oldKeyNames) do
local value = oldDataStore:GetAsync(p.UserId..keyName) -- make sure to do error handling here
oldData[keyName] = value
end
return oldData
end
The datastore now saves a table. However, when opening the DataStore with @Crazyman32’s datastore editor, the table is there, but Credits aren’t. I’m probably doing something wrong here.
local DataStoreService = game:GetService("DataStoreService")
local Currency = DataStoreService:GetDataStore("Currency","global")
local currencyTypes = {}
local saveData = function(player)
for _, currency in pairs(player.Currency:GetChildren()) do
end
Currency:SetAsync("CurrencyTypes"..player.UserId, currencyTypes)
end
game.Players.PlayerAdded:Connect(function(player)
wait(6)
saveData(player)
end)
Edit: Nevermind.
I completely forgot to put in “currencyTypes[currency.Name] = currency.Value” on line 7.
Question though, @EchoReaper
How do developers have leaderboards for kills & stuff like that? I haven’t been able to figure that out yet, but it’s probably super simple.
On another note, I’m having problems with GetAsync() currently. Pretty much the last thing I’m having problems with and then I’ll be good to go. I intend on running both systems for about two weeks or so, notify players about the integration, and then remove the previous old buggy system.
Neither of those options seem efficient enough to me.
I pretty much just need to be able to view the information for both values, Credits & Redshifitium. Perhaps I’m just not understanding the two solutions.
Actually, I played around with it a bit more and I finally figured out how to use it.
Didn’t realize “return fldr” meant it was giving me a folder with the table.convertr.
Would like to thank @EchoReaper, @Nightrains, @Fm_Trick and @AllenTheNomad for assisting me in rewriting my datastore system. If I could, I’d accept all four of you as a solution, but I don’t have that option sadly.
Is this a good way to save data every minute? Or would this cause the datastore to crash like it is currently?
This would also work alongside a function to save data when a player leaves.
while true do
wait(60)
for _, plr in pairs(game.Players:GetPlayers()) do
saveData(plr)
end
end
“saveData” doesn’t complete instantly I’m presuming, so you should do a check whether “plr” is still in-game (i.e. is parented under Players) since you obtain the player list at some point in time before the call happens. In other words suppose every call takes 1 second and there are 20 players in-game, the call for the 20th player happens 20 seconds later, and they may have already left the server (and thus had their data saved through the PlayerRemoving handler).
local Players = game:GetService("Players")
while wait(60) do
for _, plr in pairs(Players:GetPlayers()) do
if plr.Parent == Players then
saveData(plr)
end
end
end
You’d need to look at how many players there are in your game, and probably toning down the autosave time to at least 120 seconds. But I don’t know why you would transfer everything except for credits.
The only reason i can see you doing this is for a ordered data store…?
I just don’t want to accidentally wipe someone’s credit data.
Settings & System are pretty easy to reset - all you’re losing is your field of view settings, or a value determining if you’re banned or not, and your previous data, which I was planning on resetting anyways.
When you save the data, do you convert the folder into a table with the module?, if the data folder has a BoolValue, when you convert the folder into a table and then this table convert it to a new folder it should give you BoolValue.