With the lovely help of @JoelBrd I have managed to piece together a sufficient DataStore that gathers all required values in order to save them.
However - I’m now at the edge of reverse-engineering the code in order to allow the values to be loaded for the Player.
I’m not necessarily asking for the answer, but merely how to get through this. Possibly to explain more indepth about tables aswell as the Wiki hasn’t been much help.
Thank you!
function System.DataSave(Player)
local PlayerData = Player:WaitForChild('PlayerData')
local Saves = {}
Saves.isPlaying = PlayerData.isPlaying.Value
local configs = {"CharacterData", "StarShipData", "Unlocked"}
for _, config_name in pairs(configs) do
local config = PlayerData[config_name]
Saves[config_name] = {}
for _, ValueObject in pairs(config:GetDescendants()) do
Saves[config_name][ValueObject.Name] = ValueObject.Value
end
end
DS1:SetAsync(Player.UserId, Saves)
end
Hi - I need to reverse it in-order to be able to call from it.
The way above shown is the saving mechanic of my game; I however need to reverse this in-order to create a functioning load mechanic, meaning all values goes to their corresponding counter part etc.
Reverse engineering is not the correct term to be using here. You’re simply trying to find the opposite method of unpacking your data structure back into an instance-based format for use during a player’s game session.
The way I’ve done this in the past is to have my data structure available in the DataModel implicitly and then instead of creating the hierarchy of data, simply copying the folder and assigning it to the player. I then run through the dictionary and apply values accordingly depending on the key, value and dimension (the function needs to be recursive to account for other tables).
When it comes to saving, I simply turn the folder structure into a primitive format where each folder represents a new table and each ValueObject with a valid value datatype and no anti-save identifiers is inserted into a respective table.
Nice, easy and convenient. Without doing this, I’d have to add some extra layers to my code such as needing to type check the current value in the iteration and then reconstruct the folder. It’s a negligible matter but data structures are capable of producing inconsistencies. This is why I use DataStores as template fillers rather than using the raw return as the player’s data set.