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

How do I save a folder of data to a player?

Asked by 4 years ago

I have a "HiddenLeaderstats" in the player that holds all of the players data. How do i save the folder

0
Not Enough Information - Please explan what type of information(values?), and where the folder is located(is it in the character or player?) CommanderCaubunsia 126 — 4y
0
player and they are int values GunzerkingBeast21 -4 — 4y
0
You would need Datastores. NIMI5Q -2 — 4y
0
DATASTORES BR NSMascot 113 — 4y

1 answer

Log in to vote
0
Answered by
mc3334 649 Moderation Voter
4 years ago

Datastores dont accept instances, so you will have to pack all of the data into a table. To do this, do the following in a server script:

DataStore = game:GetService("DataStoreService"):GetDataStore("Data")

game.Players.PlayerRemoving:Connect(function(plr)
    local saveTable = {}
    for _,v in pairs(plr.HiddenLeaderstats:GetChildren()) do
        table.Insert(saveTable,v.Name,v.Value)
    end
    pcall(function()
        DataStore:SetAsync(plr.UserId,saveTable)
    end)
end)

game.Players.PlayerAdded:Connect(function(plr)
    wait(1)
    local data = pcall(function()
        return DS:GetAsync(plr.UserId)
    end)
    for i,v in pairs(data) do
        local value = plr.HiddenLeaderstats:FindFirstChild(i)
        if not value then return end
        value.Value = v
    end
end)

This will save all data in a hidden folder under the player named "HiddenLeaderstats". It will pack and unpack all data under the folder, but will NOT make the data values when the player joins. I hope this helped.

Ad

Answer this question