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

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

Asked by 2 years ago

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

Log in to vote
0
Answered by 2 years ago

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.

Ad

Answer this question