Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

4 comments

0

Not Enough Information - Please explan what type of information(values?), and where the folder is located(is it in the character or player?)

0

player and they are int values

0

You would need Datastores.

0

DATASTORES BR

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.