You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to save multiple Values inside of a folder.
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.
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.
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
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.