All of your code of just dealing with bool values? You should have seen how much code has been duplicated and changed the design.
There are far better ways of storing data than just putting value objects into the players model.
If you need to use these value objects create a function to make them. You hard code everything which is not how things should be done. Instead use loops and the correct table structures to setup, save and load data.
You error could be down to a lot of things in your code as it is not easy to add or remove itemst from a array without changing how other data is loaded.
In addition to this you have a lot of infinate loops which will cause errors and other issues if the player leaves the games.
An auto save should not be linked per player and should go through and save player data who are in the game.
There is a lot that needs to be looked at in your code and this is just one solution. There are better solutions which you should look into and this code does not account for any data store errors. I would also reccomend that you split this code up into modules.
As this code uses a differnt save / load format I have changed the key prefix to act as a new save.
Example:-
007 | "The Classic ROBLOX Fedora" |
028 | local function mkInstance(insType, name, val) |
029 | local tmp = Instance.new(insType) |
037 | local tmpStats = Instance.new( "Folder" ) |
040 | for folderName, itemList in pairs (statsSetup) do |
041 | local folder = mkInstance( "Folder" , folderName) |
043 | for _, itm in pairs (itemList) do |
044 | local tmpItem = mkInstance( "BoolValue" , itm, false ) |
045 | tmpItem.Parent = folder |
048 | folder.Parent = tmpStats |
052 | local ds = game:GetService( "DataStoreService" ):GetDataStore( "Clothing" ) |
054 | game:GetService( 'Players' ).PlayerAdded:Connect( function (plr) |
056 | local data = ds:GetAsync(prefix .. tostring (plr.UserId)) |
057 | local stats = tmpStats:Clone() |
062 | for folderName, itemList in pairs (data) do |
065 | local folder = stats:FindFirstChild(folderName) |
069 | for _, itm in pairs (itemList) do |
070 | local plrStats = folder:FindFirstChild(itm) |
072 | plrStats.Value = true |
081 | for _, child in pairs (stats:GetChildren()) do |
086 | local function saveData(plr) |
091 | for _, folder in pairs (plr:GetChildren()) do |
092 | if folder:IsA( "Folder" ) then |
094 | for _, itm in pairs (folder:GetChildren()) do |
096 | tmp [ #tmp+ 1 ] = itm.Name |
099 | data [ folder.Name ] = tmp |
103 | ds:SetAsync(prefix .. tostring (plr.UserId), data) |
107 | game:GetService( 'Players' ).PlayerRemoving:Connect( function (plr) |
112 | game:BindToClose( function () |
113 | for _, plr in pairs (game:GetService( "Players" ):GetPlayers()) do |
This is a lot of code to look at but please comment if you do not understand how it works.