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.
My question is: How do I loop through all the folder’s contents and save/load them?
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.