I have over 100,000 visits on my game and today is the first time that my DataStore has failed. I’m a new developer and I tried for an hour to figure out what happened but I can’t figure out what caused this DataStore to fail. I joined one of my servers because I kept getting complaints that the server wasn’t acting right and some of the scripts weren’t working how they were supposed to so I shut down the server and one of the players that were in the server when it shutdown lost all of their leaderstats. Luckily the leaderstats were only there to tell the players how long they have played the game but still, this worries me because I’m planning on using the same DataStore for a new game that I’m working on. The in-game currency is going to be a big part of this new game because you will be able to buy the currency with Robux.
DataStore:
game.Players.PlayerRemoving:connect(function(player)
local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Save")
local statstorage = player:FindFirstChild("leaderstats"):GetChildren()
for i = 1, #statstorage do
datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
print("saved data number "..i)
end
print("Stats successfully saved")
end)
game.Players.PlayerAdded:connect(function(player)
local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Save")
player:WaitForChild("leaderstats")
wait(1)
local stats = player:FindFirstChild("leaderstats"):GetChildren()
for i = 1, #stats do
stats[i].Value = datastore:GetAsync(stats[i].Name)
print("stat numba "..i.." has been found")
end
end)