I was recently messing around with data store and a couple tutorials later I ended up with this, which I like very much except for the fact that it errors on.
It errors on the line that says if i % 2 == 0 then... So on and so on
It says it errors because its arithmetic (a string value)
Heres the code
local DS = game:GetService("DataStoreService"):GetDataStore("39001837")
local DataFile = game:GetService("ServerStorage"):WaitForChild("DataFile")
local autoSaveInterval = 60
game.Players.PlayerAdded:connect(function(player)
local playerFolder = Instance.new("Folder", DataFile)
playerFolder.Name = player.Name
local Units = Instance.new("IntValue", playerFolder)
Units.Name = "Units"
local Crystals = Instance.new("IntValue", playerFolder)
Crystals.Name = "Crystals"
local GetAsync = DS:GetAsync(player.UserId)
if GetAsync then
print("Space used ".. game:GetService("HttpService"):JSONEncode(GetAsync):len().."/260000")
for i,v in pairs(GetAsync) do
print(i,v)
if i % 2 == 0 then
DataFile[player.name].playerFolder:FindFirstChild(GetAsync[i - 1]).Value = v
end
end
end
end)
local function saveData(player)
local savedData = {}
for i,v in pairs(DataFile[player.Name].playerFolder:GetChildren()) do
savedData[#savedData + 1] = v.Name
savedData[#savedData + 1] = v.Value
end
DS:SetAsync(player.UserId, savedData)
end
game:BindToClose(function()
for i, player in pairs(game.Players:GetPlayers()) do
saveData(player)
end
end)
game.Players.PlayerRemoving:connect(function(player)
saveData(player)
end)
Does anyone have any ideas im pretty sure its a simple fix. :)
Thank you for your time.

2 comments
Check that the data stored in the key is correct, it is common to have redundant data in keys.
What do you mean?