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

I'm trying to get datastore to save a table of values but it only saves one?

Hi, I'm trying to create a for loop that gets variables inside the players folder but every time I try I get and error or I only get one. For what I'm doing I can't use json it needs to be a global variable because I need to be able to script adding new values.

game.Players.PlayerRemoving:Connect(function(player)--player leaving the game
	local save = {}--the table of data
	
	for _, Child in pairs(player.chars:GetChildren()) do --gets the children of the chars folder
		table.insert(save, Child.Value) --should insert the children in but it only inserts one
	end
	
	dataStore:SetAsync(player.UserId, save)--saves the table 
end)

1 answer

Edit: I've figured out the answer to my question, The trick is that I have to put a for loop to continuously check the datastore when getting the datastore values and then also create a new string value with the data in it. you see before I had it set to only get the datastore, which only had one value and to just print them but not put them into any meaningful use.

This discussion is preserved as it was. New answers, comments, and votes are closed.