I'm getting an error on line 32 that, not sure why or how. I tried changing the DB name, since it's the root of the hierarchy.
Picture https://gyazo.com/86638338ee70f1b6788fe096bcdf1a9b
local AUTO_SAVE = true
local TIME_BETWEEN_SAVES = 60
local PRINT_OUTPUT = true
local SAFE_SAVE = true
local players = game:GetService("Players")
local dataStoreService = game:GetService("DataStoreService")
local leaderboardData = dataStoreService:GetDataStore("I8SB90AnsjGJAK?FA*Mz")
local function Print(message)
if PRINT_OUTPUT then print(message) end
end
local function SaveData(player)
wait(2.5)
if player.userId < 0 then return end
player:WaitForChild("BackendData")
wait()
local BackendData = {}
for i, stat in pairs(player.BackendData:GetChildren()) do
table.insert(BackendData, {stat.Name, stat.Value})
end
leaderboardData:SetAsync(player.userId, BackendData)
Print("Saved "..player.Name.."'s data")
end
local function LoadData(player)
if player.userId < 0 then return end
player:WaitForChild("BackendData")
wait()
local leaderboardStats = leaderboardData:GetAsync(player.userId)
for i, stat in pairs(leaderboardStats) do
local currentStat = player.BackendData:FindFirstChild(stat[1])
if not currentStat then return end
currentStat.Value = stat[2]
end
Print("Loaded "..player.Name.."'s data")
end
players.PlayerAdded:connect(LoadData)
players.PlayerRemoving:connect(SaveData)
if SAFE_SAVE then
game.OnClose = function()
for i, player in pairs(players:GetChildren()) do
SaveData(player)
end
wait(1)
end
end
while AUTO_SAVE do
wait(TIME_BETWEEN_SAVES)
for i, player in pairs(players:GetChildren()) do
SaveData(player)
end
end

8 comments
What exactly is BackendData?
It's an IntValue inside of the player that stores the Money, JailTime, and if the player owns the car or not. Then inside the player we have leaderstats that holds Jail Time and Money and gets the values from BackendData, it's data that can't be edited besides the admin panel. If you need a clarification I can give one.
How can whitespace cause you this error?
good luck
@PhantomVisual your answer is wrong in so many ways
@incapaxx My mistake. Didn't even test it in-studio, just assumed. Thanks for telling me!
Idk, it still works. It just doesn't save when the player leaves, only saves every 60 seconds. It's fine. I put a disclaimer every 60 seconds to wait every 60 seconds for their data to save.
Sorry, but I'm closing this question. The line that you claim to be causing you issues is just whitespace, which means you did not post full code, or you made changes to the code that affected the line count, and there are multiple occurrences of you calling the
pairsfunction; which call topairscauses your problem?