Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to save values in a folder using GetChildren()?

Asked by 5 years ago
Edited 5 years ago

I already find this [https://devforum.roblox.com/t/folder-getchildren-datasave/284730] but i dont know how to use this informations to make a working script. I cant save all my values one by one cause i have 18 values... My save script (for one value) actually look like this:

01local DSS = game:GetService("DataStoreService")
02 
03local PlayerCash = DSS:GetDataStore("Money")
04wait(0.04)
05game.Players.PlayerAdded:Connect(function(Player)
06    Player.CharacterAdded:Connect(function(Character)
07        local Cash = Player.Folder.Money
08        Cash.Value = PlayerCash:GetAsync(Player.userId) or 0
09 
10        game.Players.PlayerRemoving:connect(function(Player)
11            PlayerCash:SetAsync(Player.userId, Cash.Value)
12        end)
13                while true do
14            wait(70)
15            PlayerCash:SetAsync(Player.userId, Cash.Value)
16            end
17    end)
18end)

and i currently trying to mix it with this (to hold more values) :

01--Saving data
02local dataToSave = {}
03 
04for i,v in pairs(playerFolder:GetChildren()) do
05     table.insert(dataToSave, v.Name)
06end
07 
08--Save the table to a key
09dataStore:UpdateAsync(key, function(oldValue)
10    --Do some kind of check if you want
11    return dataToSave
12end)
13 
14--Loading data
15local loadedData = --Load data from key
View all 21 lines...
0
Sorry for my bad english scorpion981 27 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Just use .:AutoSaver:. by Clirex and replace all the word leaderstats for the name of your folder.

Ad

Answer this question