hi for the past few months i've been using this script for stats data store. but sometimes your data will be resetted. is there a way i could fix it?

local DataStore = game:GetService("DataStoreService")

local myDataStore = DataStore:GetDataStore("EpicStorage")

	game.Players.PlayerAdded:Connect(function(player)
		local leaderstats = Instance.new("Folder")
		leaderstats.Name = "leaderstats"
		leaderstats.Parent = player
			
		local minutes = Instance.new("IntValue")
		minutes.Name = "Minutes"
		minutes.Parent = leaderstats
		
		local data
		local success, errormessage = pcall(function()
			data = myDataStore:GetAsync(player.UserId.."-minutes")
	end)
	
	if success then
		minutes.Value = data
	else
		print("Error when saving data")
		warn(errormessage)
	end
end)
	
game.Players.PlayerRemoving:Connect(function(player)
	
	local success, errormessage = pcall(function()
		myDataStore:SetAsync(player.UserId.."-minutes",player.leaderstats.Minutes.Value)
	end)
	
	if success then
		print("Data successfully saved!")
	else
		print("Data save is unsuccessful!")
		warn(errormessage)
	end
end)

4 comments

0

I'm pretty sure there is no way to prevent it, since it's a roblox problem. You can make another datastore to have as an backup, but there is still a chance BOTH of these will fail and your data gets resetted.

0

I'm pretty sure you can kick the player when something goes wrong.

0

Kicking won't do anything, since when the player joins the data will be resetted, and when you kick him it will save the data AFTER it has been resetted.

0

auto saves?