local DataStoreService = game:GetService("DataStoreService")
local MainDataStore = DataStoreService:GetDataStore("MainDataStore")
local playerUserId = "Player_"..player.UserId
local MainData
local success, errormessage = pcall(function()
MainData = MainDataStore:GetAsync(playerUserId)
end)
if success then
print("Loaded in successfully")
print(MainData)
totalPeopleInfected.Value = MainData["TotalInfected"]
peopleInfected.Value = MainData["Infected"]
money.Value = MainData["Money"]
survivors.Value = MainData["Survivors"]
totalSurvivors.Value = MainData["TotalSurvivors"]
else
print("There was an error retrieving data")
warn(errormessage)
end
It does the success part of the if statement but then I get this error
09:27:11.667 - ServerScriptService.Leaderstats:91: attempt to index nil with 'TotalInfected'
Any ideas? (This is in a player added function, I only copied the neccessey parts)

4 comments
On your line "print(MainData)" does it print "nil"?
yes
i would assume that it didn't save correctly, because it looks like the loading works fine
Yeah maybe the table is not saved as the way it get received.