I have a "HiddenLeaderstats" in the player that holds all of the players data. How do i save the folder
COMMUNITY QUESTION
How do I save a folder of data to a player?
1 answer
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
Not Enough Information - Please explan what type of information(values?), and where the folder is located(is it in the character or player?)
player and they are int values
You would need Datastores.
DATASTORES BR