DataStoreService: InternalError: The data store is deleted. API: GetAsync

Just.. What?

As you saw in the title,
Roblox has been treating datastores pretty weirdly right now..
I got this error, and i’ll be completely honest, i don’t think this is my fault. Here is the code:

local dss = game:GetService("DataStoreService")

local coinsData = dss:GetDataStore("CoinsData")
local winsData = dss:GetDataStore("WinsData")
local stickersData = dss:GetDataStore("StickersData")

local stickersFolder = script.Parent.Stickers

game.Players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Parent = leaderstats
	
	local success, currentCoins = pcall(function()
		return coinsData:GetAsync("Coins_"..player.UserId)
	end)
	
	if success then
		coins.Value = currentCoins or 0
	else
		coins.Value = 0
	end
	
	local wins = Instance.new("IntValue")
	wins.Name = "Wins"
	wins.Parent = leaderstats
	
	local success2, currentWins = pcall(function()
		return winsData:GetAsync("Wins_"..player.UserId)
	end)

	if success2 then
		wins.Value = currentWins or 0
	else
		wins.Value = 0
	end
	
	local stickers = Instance.new("Folder")
	stickers.Name = "OwnedStickers"
	stickers.Parent = player
	
	local success3, stickerTable = pcall(function()
		return stickersData:GetAsync("Stickers_"..player.UserId)
	end)

	if success3 then
		if stickerTable then
			for _, sticker in pairs(stickerTable) do
				local stickerClone = stickersFolder:FindFirstChild(sticker)
				if stickerClone then
					stickerClone:Clone().Parent = stickers
				end
			end
		end
	else
		warn("Couldn't load stickers")
	end
	
	local equippedStickers = Instance.new("Folder")
	equippedStickers.Name = "EquippedStickers"
	equippedStickers.Parent = player
	
	local canEnterGame = Instance.new("BoolValue")
	canEnterGame.Name = "CanEnterGame"
	canEnterGame.Value = false
	canEnterGame.Parent = player
end)

function save(player)
	local success, err = pcall(function()
		coinsData:SetAsync("Coins_"..player.UserId, player.leaderstats.Coins.Value)
	end)

	if success then
		print("Saved")
	else
		warn("Couldn't save", err)
	end

	local success2, err2 = pcall(function()
		winsData:SetAsync("Wins_"..player.UserId, player.leaderstats.Wins.Value)
	end)

	if success then
		print("Saved")
	else
		warn("Couldn't save", err2)
	end

	local stickersTable = {}
	for _, sticker in pairs(player.leaderstats.OwnedStickers:GetChildren()) do
		table.insert(stickersTable, sticker.Name)
	end
	local success3, err3 = pcall(function()
		winsData:SetAsync("Stickers_"..player.UserId, stickersTable)
	end)

	if success then
		print("Saved")
	else
		warn("Couldn't save", err3)
	end 
end

game.Players.PlayerRemoving:Connect(function(player)
	save(player)
end)

game:BindToClose(function()
	for _, player in pairs(game.Players:GetPlayers()) do
		save(player)
	end
end)

It seems to happen because I deleted a datastore on the dash board so roblox tries to get a “nil” datastore essentially (At least from what i saw in the error.)

It looks like a error in the GetAsync too ho. So i don’t know.

Any help is appreciated

Try rename the datastore.

Also you saved stickers to the wrong datastore and OwnedStickers is not inside your leaderstats so your loop will flag

ok! so i suggest making a new datastore :face_exhaling:

local coinsData = dss:GetDataStore("CoinsData_v2")

now i also found some bugs in your script

  1. lil bug here
local success2, err2 = pcall(function()
	winsData:SetAsync("Wins_"..player.UserId, player.leaderstats.Wins.Value)
end)

if success then --wrong variable
	print("Saved")
else
	warn("Couldn't save", err2)
end

it shouldve been

if success2 then
	print("Saved")
else
	warn("Couldn't save", err2)
end

and also that same bug appears for success3 :eyes:

  1. next you also saving stickers to the wrong datastore
winsData:SetAsync("Stickers_"..player.UserId, stickersTable)

it shoudlve been

stickersData:SetAsync("Stickers_"..player.UserId, stickersTable)
  1. you also got this
player.leaderstats.OwnedStickers

which is wrong because owndstickers are not in leaderstats, so it actually should be

for _, sticker in pairs(player.OwnedStickers:GetChildren()) do
  1. aaand finally use setasync so data can be overwritten if 2 servers does it at once (updateasync cant do tht)
coinsData:UpdateAsync("Coins_"..player.UserId,function(old)
	return player.leaderstats.Coins.Value
end)

  1. now fix your bindtoclose so it waits until saves finish
game:BindToClose(function()
	for _, player in pairs(game.Players:GetPlayers()) do
		save(player)
	end
	task.wait(3)
end)

welp thats all! person feedback from me, i suggest you save datastores per player instead of multiple stores! like this:

PlayerData_123456 = {
    Coins = 10,
    Wins = 5,
    Stickers = {"Star","Heart"}
}

farrr faster and safer

alright thats all. hope that helps :smile:

1 Like

Thanks for the response.

I’ll try it out and see if it works..

Thank you so much bro, you fixed all my problems.

Even the stickers are working flawlessly

Also if you’re curious here are the new code with the new changes.
(I’ll look up to that “table” data you mentioned, it looks cool and cleaner)

local dss = game:GetService("DataStoreService")

local coinsData = dss:GetDataStore("CoinsData_")
local winsData = dss:GetDataStore("WinsData_")
local stickersData = dss:GetDataStore("StickersData")

local stickersFolder = script.Parent.Stickers

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Parent = leaderstats
	
	local success, currentCoins = pcall(function()
		return coinsData:GetAsync("Coins_"..player.UserId)
	end)
	
	if success then
		coins.Value = currentCoins or 0
	else
		coins.Value = 0
	end
	
	local wins = Instance.new("IntValue")
	wins.Name = "Wins"
	wins.Parent = leaderstats
	
	local success2, currentWins = pcall(function()
		return winsData:GetAsync("Wins_"..player.UserId)
	end)

	if success2 then
		wins.Value = currentWins or 0
	else
		wins.Value = 0
	end
	
	local stickers = Instance.new("Folder")
	stickers.Name = "OwnedStickers"
	stickers.Parent = player
	
	local success3, stickerTable = pcall(function()
		return stickersData:GetAsync("Stickers_"..player.UserId)
	end)

	if success3 then
		if stickerTable then
			for _, sticker in pairs(stickerTable) do
				local stickerClone = stickersFolder:FindFirstChild(sticker)
				if stickerClone then
					stickerClone:Clone().Parent = stickers
				end
			end
		end
	else
		warn("Couldn't load stickers")
	end
	
	local equippedStickers = Instance.new("Folder")
	equippedStickers.Name = "EquippedStickers"
	equippedStickers.Parent = player
	
	local canEnterGame = Instance.new("BoolValue")
	canEnterGame.Name = "CanEnterGame"
	canEnterGame.Value = false
	canEnterGame.Parent = player
end)

function save(player)
	local success, err = pcall(function()
		coinsData:SetAsync("Coins_"..player.UserId, player.leaderstats.Coins.Value)
	end)

	if success then
		print("Saved")
	else
		warn("Couldn't save", err)
	end

	local success2, err2 = pcall(function()
		winsData:SetAsync("Wins_"..player.UserId, player.leaderstats.Wins.Value)
	end)

	if success2 then
		print("Saved")
	else
		warn("Couldn't save", err2)
	end

	local stickersTable = {}
	for _, sticker in pairs(player.OwnedStickers:GetChildren()) do
		table.insert(stickersTable, sticker.Name)
	end
	local success3, err3 = pcall(function()
		stickersData:SetAsync("Stickers_"..player.UserId, stickersTable)	
	end)

	if success3 then
		print("Saved")
	else
		warn("Couldn't save", err3)
	end 
end

game.Players.PlayerRemoving:Connect(function(player)
	save(player)
end)

game:BindToClose(function()
	for _, player in pairs(game.Players:GetPlayers()) do
		save(player)
	end
	task.wait(3)
end)

great! your welcome!! :smile: :smile: ​​​​​​​​​​​

1 Like

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