How to save and load values inside of a folder?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want to save multiple Values inside of a folder.

image

  1. What is the issue? Include screenshots / videos if possible!

I made a table and saved it into a datastore, the problem is I don’t know how to load them. it doesn’t work.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have looked at the DevHub and found similar topics, but none that actually solved my problem.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

this is my code:

local LevelCollectibles = {}

for _, LC in pairs(workspace.LevelCollectibles:GetChildren()) do
	LevelCollectibles[LC.Name] = LC.Value
	
	print(LevelCollectibles)
end

I put the table inside SetAsync(). But, I don’t know how to load them.

1 Like

First, use GetAsync() to retrieve the data.

local data
local success, err = pcall(function()
    data = yourDataStore:GetAsync(--[[whatever you use to access the data store goes here]])
end)
if success and data then
    --manually get the names
    print(data["1-1"]) --the first value in your folder has been saved here
end

And if you want to add the values back to the folder:

for key, value in pairs(data) do
    yourFolder[key].Value = --value here
end
1 Like

In addition, you will have to create the folder and values when the player joins and set their value using GetAsync.

2 Likes

Can you show me how you saved it?

Your situation is somewhat complicated, because in my opinion, you want to save a Name, along with an Assigned Value.

Here is a Solution that I would use in this case:

local DSS = game:GetService("DataStoreService")
local Data = DSS:GetDataStore("LevelCollectibles")

local function LoadData(plr)
	
	local collectFolder = plr.LevelCollectibles --Folder to Store Data Loaded

	--Load
	local async = Data:GetAsync(plr.UserId) or {"1-1:100"}

	for _,v in pairs(async) do
		
		local splited = string.split(v,":")
		local name = splited[1]
		local value = splited[2]
		
		local collect = Instance.new("StringValue")
		
		collect.Name = name
		collect.Value = tonumber(value)
		
		collect.Parent = collectFolder
		
	end
	
	
end

local function SaveData(plr)
	
	local LevelCollectibles = plr.LevelCollectibles

	local LevelCollectiblesTable = {}

	for _, LC in pairs(LevelCollectibles:GetChildren()) do
		
		local textToSave = LC.Name..":"..LC.Value
		
		table.insert(LevelCollectiblesTable,textToSave)
		
		print(LevelCollectibles)
	end
	
end

I created the Script with the idea that each player would have their own Save, but the idea is the same for any case, just adapt as necessary.

I’m new to helping here on the Forum, if I managed to answer your question, please mark it as the answer <3

I hope it helped by at least teaching you a new way to save information.

1 Like

You can save a dictionary. I have done so in my own game and it has worked fine.

Sorry for being so old :0
I learned how to script about 5 years ago.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.