Might be too much to ask for, but is there a way to get every player’s datastore from a single script, and change the datastore’s values? (And by every player I mean EVERY, even offline/inactive ones)
I know how to overwrite a specific person’s datastore, or of everyone in the same server, but for everyone that ever played? Is there a way to do that or I have to use a similar alternative?
I save data via custom script and tables, not leaderstats
edit: I also specified I need to know if I can change datastore for EVERY player, even ones not in the server or that aren’t currently playing. Is there an actual way?
It’s possible yet highly difficult and not very efficient, I would suggest immediately upon a player joining you detect if their data is the old version (the one you want to change) and immediately changing it to the new version that you want.
Aight I hear y’all, not possible, well technically possible but as efficient as killing fire with gasoline.
Yes. But how would I do that without deleting the og data? And how do I make it detect if a table value is missing? There’s quite a few things to consider, like the ones I mentioned rn
local DSS = game:GetService("DataStoreService") -- Service
local Store = DSS:GetDataStore("characterData") -- DataStore
local Storage = {} -- Stores Player Data
local Key = "Player_" -- Key to get data
game.Players.PlayerAdded:Connect(function(player)
local Success, Data = pcall(function() -- protected call
return Store:GetAsync(Key..player.UserId) -- returns Data if Player has any
end)
if Success then -- if Accessed DataStores
if Data then -- If Player has Data
Storage[player.UserId] = Data -- Applies Table data to Custom Player Data
else --If Player has no Data
Storage[player.UserId] = {
characters = {
FighterONE = {
Attacks = {
Attack1 = 1,
Attack2 = 2,
Attack3 = 3,
Attack4 = 4,
Attack5 = 5,
Attack6 = 6
},
currentSkin = "Standard"
},
FighterTWO = {
Attacks = {
Attack1 = 1,
Attack2 = 2,
Attack3 = 3,
Attack4 = 4,
Attack5 = 5,
Attack6 = 6
},
currentSkin = "Standard"
},
}
}
end
else
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Success = pcall(function()
Store:SetAsync(Key..player.UserId, Storage[player.UserId]) -- Saves Player Table
end)
if Success then
print("Player Left, Data Saved.")
else
print("Player left but Data Saving Failed.")
end
end)
Like you see, if it’s a new player no worries, it’ll create the data table I wish, but if it’s an old player, how will I have it detect what’s missing at a specific location? I need it to detect if there’s a new fighter and to add it if the player didn’t have it and stuff like that, you get what I mean
EDIT: The script works just fine and everything works as intended, I only need to know how to get it updated for each player with old data that enters, without it resetting if they changed some stuff (like character attack values and such), but at the same time adding the “FighterTHREE” table
If a player’s save file has a set amount of data that could possibly be stored in it, you could create a reference/model table of what a maxed out save file looks like.
From there, you would use a metatable to automatically index and return data from the model table and transfer it into the player’s save file/table.
This would make getting and setting data errorless and easy. Here’s an example.
so by doing this I transfer the info, but not the values if some exist
Example: Let’s say there’s 3 values inside a table, they’re like 14, 18 and 55, then I need to add a 4th one, it’ll create the 4th one and leave the og 3 as 14, 18 and 55? (basically doesn’t overwrite existing ones and only adds whatever isn’t added from reference table)