In my game, Spinning Thing of Doom 2, people complained that, at random, their data was deleted. I made an update a few hours ago, hoping to fix it. As of now, I have 3 values that go inside the player; Cash, Points (in leaderstats), and Purchased (a string value with the inventory of bought items).
function decide(player,leaving) if leaving then if not set(player) then update(player) end else get(player) names:SetAsync(player.userId,player.Name) -- this is set up such that a backup store is created end end game.Players.PlayerAdded:connect(function(player) for i = 0,60,.03 do print("getting stats...") wait() if player:FindFirstChild("leaderstats") and player:FindFirstChild("Purchased") then decide(player,false) break end end print("loaded") end) game.Players.PlayerRemoving:connect(function(player) decide(player,true) end)
This is the logic behind the saving. Then I have a few "shortcut" funtions called get(), update(), and set(), each with player as its argument. The for loop at the starts waits a full minute of trying to load the stats of the player, but I have no idea if thats a good idea or there is any method unknown to me that would make life easier...
Sorry for the giant wall of code and text, but I need to know if there is a more... dynamic way to make stores more solid.
Thanks! ~Tiger