I am making a game which has multiple save files, 3 to be exact, for players to save/load their data. I have a time played datastore which is consistent over all save files, plus money and items which is different for each save file. I thought of created a seperate key for each save file, so it would be like:
local key = plr.UserId.."Key"..chosenfile
The thing about that is that it would change the time played only for that save file, and every other save wouldn’t carry the timeplayed. I also thought of created seperate folders and values for each save file and loading them all, and saving them all at the end. The problem with that would be that it would be very inefficent. Is there any way I can save these tables? Also, should I use jsonencode and decode or would it be fine just to save the tables.
The best to make a players general time played seems to be making a separate value from the load files and start counting up when the players load the file. Save as they leave.
this is quite easy actually you can use the scope of your datastore
--the second argument of DSservice:GetDatastore is the scope, it defaults to "Default" if there is none specified
DSservice:GetDatastore("DatastoreName",ChosentFile):GetAsync(plr.UserId)
--this also works for ordered datastores
if you have that in the datastore then yes but there’s no way around that besides one big datastore but that could fill up or if it corrupts then they have lost literally everything
So I use 2 datastores? 1 for save files and 1 for the played time?
local temp = {
TimePlayed = 0,
TotalItemsBought = 0,
TotalMoneyEarned = 0,
Money1 = 0,
Money2 = 0,
Money3 = 0,
ItemsUnlocked1 = {},
ItemsUnlocked2 = {},
ItemsUnlocked3 = {},
}
return temp
Thats how my current one looks like.
I am confused. My code is like: Data = PlrDatastore:GetAsync(Plr.UserId … key.Value) That way, I would have to load less datastore things than before. How would I get the stats?
What I was mentioning is getting the time outside of load saves, if your referring to getting the times for each saved file, that would probably be more easy.
Lets say we have a datastore and we want to add a Time value to that datastore.
game.Players.PlayerAdded:Connect(function(player)
local TimePlayed = Instance.new("IntValue", player)
TimePlayed.Name = "TimePlayed"
TimePlayed.Value = DataStore:GetAsync(player.UserId)
if playerClickedLoadFile then
spawn(function() -- So the rest of the code can continue if there is more below
while true do
wait(1)
player.TimePlayed.Value = player.TimePlayed.Value + 1
end
end)
end
end)
game.Players.PlayerRemoving:Connect(function()
-- Pcall for saving stats
end)