DataStores wiped for most players in wake of this latest Roblox outage

So this latest outage wiped the data of most of our players on our DataStore, and very few have had their data stay intact.

How can we keep this from happening again? I’m not well versed in DataStores.

Here’s our DataStore’s script:

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("TimeData")
local BadgeService = game:GetService("BadgeService")


game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local Time = Instance.new("IntValue")
	Time.Name = "Minutes"
	Time.Parent = leaderstats

	local playerUserId = "Player"..player.UserId

	local data 

	local success, errormessage = pcall(function()
		data = myDataStore:GetAsync(playerUserId) 
	end)


	if success then
		Time.Value = data  --loads data when player joins
	end

	while wait(60) do
		player.leaderstats.Minutes.Value = player.leaderstats.Minutes.Value + 1 --makes time go up by one every minute
         end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local playerUserId = "Player"..player.UserId

	local data = player.leaderstats.Minutes.Value

	myDataStore:SetAsync(playerUserId, data)           --saves data when player leaves game
	print(player.Name,"left the game. They have",data,"minutes.")
end)

I’m also worried the same has occurred with my other game that utilizes DataStores. Here’s its script:

local stat = "Points"
local startamount = 0 

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("LeaderStatSave")

game.Players.PlayerAdded:connect(function(player)
print("welcome", player.Name, "! heres your points.")
local leader = Instance.new("Folder",player)
leader.Name = "leaderstats"
local Cash = Instance.new("IntValue",leader)
	Cash.Name = stat
	local cpoints = Instance.new("IntValue",leader)
	cpoints.Name = "Current Points"
	cpoints.Value = 0
	Cash.Value = ds:GetAsync(player.UserId) or startamount
	ds:SetAsync(player.UserId, Cash.Value)
	Cash.Changed:connect(function()
		if player.leaderstats.Points.Value <= -1 then
			print(player.Name, "triggered an overflow. returning to max points...")			
			player.leaderstats.Points.Value = 9223372036854780000
			ds:SetAsync(player.UserId, player.leaderstats.Points.Value)
			wait(60) --stop spamming the datastore!!!
		end
	end)
end)

game.Players.PlayerRemoving:connect(function(player)
	print(player.Name, "left. saving points... they have", player.leaderstats.Points.Value, "points.")
	ds:SetAsync(player.UserId, player.leaderstats.Points.Value) --Change "Points" to the name of your leaderstat.
	local success, err = pcall(function()
		return ds:SetAsync(player.UserId, player.leaderstats.Points.Value)
	end)

	if success then
		print("point save successful")
	else
		warn("point save failed!")
	end
end)

Please provide code samples in your responses if you can, I learn best from example!

This datastore doesn’t account for those type of situations where the player doesn’t shutdown properly. A bindtoclose() function might help, but I recommend learning the ProfileService datastore.

I’m attempting to learn ProfileService but the tutorials are not providing much help. Despite mimicking the code for this one involving leaderstats, I could not get it to function.

I have no earthly idea what I’m doing.

In your code you’re not using pcall when setting data as well as that you’re not checking if the data has been loaded before saving it.

local DataStoreService = game:GetService("DataStoreService")
local BadgeService = game:GetService("BadgeService")

local Players = game:GetService("Players")
local myDataStore = DataStoreService:GetDataStore("TimeData")

Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local Time = Instance.new("IntValue")
	Time.Name = "Minutes"
	Time.Parent = leaderstats

	local playerUserId = "Player"..player.UserId

	local data 

	local success, errormessage = pcall(function()
		data = myDataStore:GetAsync(playerUserId) 
	end)


	if success then
		player:SetAttribute("DataLoaded", true)
		Time.Value = data or 0 --loads data when player joins
	end

	while player do
		player.leaderstats.Minutes.Value += 1 --makes time go up by one every minute
		task.wait(60)
	end
end)

Players.PlayerRemoving:Connect(function(player)
	if player:GetAttribute("DataLoaded") ~= true then -- If the players data has not been loaded we don't want to overwhite it
		warn(string.find("%s data was not saved as it failed to load."), player.Name)
		return
	end
	local playerUserId = "Player"..player.UserId
	local data = player.leaderstats.Minutes.Value
	
	local success, errormessage = pcall(function()
		myDataStore:SetAsync(playerUserId, data)           --saves data when player leaves game
	end)
	
	if not success then
		warn(string.find("%s data failed to load."), player.Name)
	end
end)

Try using my method of ProfileService, DataService.

It’s basically ProfileService but identical to DataStore service. Documentation is linked on the post. Hope you get your situation sorted out.

Just a note, you should be able to use the same key names if I am not mistaken.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.