Ability to save and load (hierarchies of) Instances to DataStore

As a Roblox developer, it is currently hard to save folders with its contents, to the datastore
If Roblox is able to address this issue, it would improve my game / my development experience because it would allow me to focus on developing my game rather than sitting and trying to figure out how to save all contents of an folder to datastore.

How it would work?
DataStore should allow developers to save data / load data, as instances. Instances can be pretty much anything, everything would be saved including properties, it’s like an exact copy saved to the datastore.

PlayerData as an template

Captuere

PlayerData after Player playing a game after an month let’s say

An example. Do you see any tables? Nope, not anymore.
	local DataStoreService = game:GetService("DataStoreService") -- Get datastore service
	local DataStore = DataStoreService:GetDataStore("PlayerData") -- Get datastore
	
	local Players = game:GetService("Players") -- Get players service
	local Template = script:WaitForChild("PlayerData") -- Datastore template folder with contents
	
	Players.PlayerAdded:Connect(function(Player) -- When player joins the game
		local SavedPlayerData = nil -- Create an variable, empty for rightnow
		
		pcall(function() -- Don't crash entire script if it fails to load saved data
			SavedPlayerData = DataStore:GetAsync(Players.UserId) -- Get saved data
		end) -- End the statment
		
		if SavedPlayerData ~= nil then -- Saved data is not empty then
			SavedPlayerData:Clone().Parent = Player -- Get saved data and clone it, to the player
		else -- Or its empty then
			Template:Clone().Parent = Player -- Clone the template datastore folder to the player
			local PlayerData = Player:WaitForChild("PlayerData") -- Get datastore folder
			DataStore:SetAsync(Player.UserId, PlayerData) -- Save the folder to the player id
		end -- End the statment
	end) -- End the statment
	
	Players.PlayerRemoving:Connect(function(Player) -- When player leaves the game
		local PlayerData = Player:WaitForChild("PlayerData") -- Get datastore folder
		DataStore:SetAsync(Player.UserId, PlayerData) -- Save the folder to the player id
	end) -- End the statment

Why it would be an great feature?

  • Less scripting, more time for other stuff.
  • Easier to write a datastore script.
  • More possibilities with less required experience and potential problems.

Why do you think, it would be an great feature? If not then why not?

3 Likes

Saving instances was a feature with Data Persistence (correct me if i’m wrong), until it got replaced with Data Stores. Roblox didn’t add instance saving to Data Stores because it’s not a good practice. As a developer/programmer, you should be willing to learn complex systems such as data base management and handling. Also, you need to visualize programming as numbers, you’ll definitely find programming much simlpler.

Less scripting is not always a good thing, and it’s not something you should be excited about. You simply need a data encoder and decoder (or simply a serializer) to overcome your issue. Use numbers/IDs as a reference to objects.

For the record, there are more possibilities when you handle raw data. Experience wise, it’s not a valid reason to say “less experience” or “easier to write”, you have the forum and developer hub for help and reference.

I don’t agree or disagree with your post, however having issues with data store structures is pretty common. It just takes time to wrap your head around it.

7 Likes

What wevetments said is exactly correct, but despite this, I’d still personally welcome the ability to save instances. My personal preference is a utility to serialize/deserialize instances during runtime (not necessarily for datastores, but just in general, effectively a way to access a system to save as RBXM/RBXMX via Lua)

I wrote a script for this some time ago because I understand there are cases where instance saving is necessary. This code was used for my player plot system. The part of the code that serializes parts is closed source, but I do have a modified version of stravant’s BitBuffer module which can be used to serialize data into compact binary formats. You can use this to compress a lot of data into a small space. It should ideally come in handy as a workaround for your current goals, since it’s the best you’re going to get for now.

https://www.roblox.com/library/3209877150/XBitBuffer

My custom version here has implemented writing Half and Minifloat formats (16 bit and 8 bit float respectively), saving complete CFrames into the buffer, and saving Vector3int16s into the buffer.

5 Likes