How do I save values in a custom folder in a Datastore?

Hey guys

I’m working on a game which has a lot of different values to save when the player leaves and when the player enters.
I have created a custom folder with everything that should be inside the player and placed it in the datastore script.
image

My question is: How do I loop through all the folder’s contents and save/load them?

Thank you!

Use Instance:GetDescendants() to receive an array of all descendants of an instance.
For example, here is a loop that runs through the descendants of an instance referred to as “DataFolder” and checks to see if a given object is a type of value.

for _, object in pairs(DataFolder:GetDescendants()) do
	if object:IsA("ValueBase") then
		-- Do something here (like add it to a table to eventually save)
	end
end

Hope this helps. If you have any further questions, let me know.

1 Like