The script I am trying to do is, the script will clone the stats which is in a folder, which is then saved into the player if they leave, its also supposed to load the stats. I am trying to use table.insert instead of saving every value in the folder manually like valuesToSave = {1.value,2.value,.........}
--Player Joins local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayerStats") game.Players.PlayerAdded:Connect(function(player) local pstats = Instance.new("Folder", player) pstats.Name = "PlayerStats" for index, child in pairs(game.Workspace.DataStore.Values:GetChildren()) do print(child,child.Value,index) local stat = child:Clone() stat.Parent = pstats end local key = "player-"..player.userId local savedValues = DataStore:GetAsync(key) for index, child in pairs(game.Workspace.DataStore.Values:GetChildren()) do child.Value = savedValues[index] end local valuesToSave = {} local children = game.Workspace.DataStore.Values:GetChildren() for i = 1,#children do table.insert(valuesToSave,i,children.Value) end DataStore:SetAsync(key, valuesToSave) print(table.concat(valuesToSave,'')) end) --Player leaves local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayerStats") game.Players.PlayerRemoving:Connect(function(player) local key = "player-"..player.userId local valuesToSave = {} local children = game.Workspace.DataStore.Values:GetChildren() for i = 1,#children do table.insert(valuesToSave,i,children.Value) end DataStore:SetAsync(key, valuesToSave) end)