So I have been using this saver for a long time, and never really thought to update it or look into it, but recently a few of my players have gotten my stats and I feel its because of this, any way to update it to make it so it doesn't do that?
> local DoAutoSave = true
> local AutoSaveInterval = 120
>
> local DataStore = game:GetService("DataStoreService"):GetDataStore('HatSave')
>
> local currentsave
> local stats
> local currentstat
> local tabletosave
>
> game.Players.PlayerAdded:Connect(function(player)
> currentsave = DataStore:GetAsync(player.UserId)
> stats = player:WaitForChild("stats")
> if currentsave then
> for i = 1,#currentsave do
> currentstat = stats:WaitForChild(currentsave[i]['Name'])
> currentstat.Value = currentsave[i]['Value']
> end
> print('Loaded stats')
> else
> print('Player is new and yes do be')
> end
> if DoAutoSave then
> spawn(function()
> repeat
> wait(AutoSaveInterval)
> if player then
> tabletosave = {}
> for _,v in pairs(player:FindFirstChild("stats"):GetChildren()) do
> tabletosave[#tabletosave+1] = {Name = v.Name,Value = v.Value}
> end
> DataStore:SetAsync(player.UserId,tabletosave)
> else
> print('Player is not there, he dipped"')
> end
> until not player
> end)
> end
> end)
>
> game.Players.PlayerRemoving:Connect(function(player)
> if player then
> tabletosave = {}
> for _,v in pairs(player:FindFirstChild("stats"):GetChildren()) do
> tabletosave[#tabletosave+1] = {Name = v.Name,Value = v.Value}
> end
> DataStore:SetAsync(player.UserId,tabletosave)
> else
> print("The man is not there")
> end
> end)
