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 4 years ago
Edited 4 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:

local DSS = game:GetService("DataStoreService")

local PlayerCash = DSS:GetDataStore("Money")
wait(0.04)
game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        local Cash = Player.Folder.Money
        Cash.Value = PlayerCash:GetAsync(Player.userId) or 0

        game.Players.PlayerRemoving:connect(function(Player)
            PlayerCash:SetAsync(Player.userId, Cash.Value)
        end)
                while true do
            wait(70)
            PlayerCash:SetAsync(Player.userId, Cash.Value)
            end
    end)
end)

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

--Saving data
local dataToSave = {}

for i,v in pairs(playerFolder:GetChildren()) do
     table.insert(dataToSave, v.Name)
end

--Save the table to a key
dataStore:UpdateAsync(key, function(oldValue)
    --Do some kind of check if you want
    return dataToSave
end)

--Loading data
local loadedData = --Load data from key
local loadedData = dataStore:GetAsync(key) --Example
for i,v in pairs(loadedData) do
      local n = Instance.new('Folder')
       n.Name = v 
       n.Parent = playerFolder
end
0
Sorry for my bad english scorpion981 27 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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

Ad

Answer this question