Datastore error deleting all data

This error seems like a very big thing to rely on not happening. Is there any way I can stop this from happening or is it a roblox bug?


In case its something with my script, heres my script

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStoreValues")
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)

	local Coldata --giving them a variable
	
	local Leveldata --giving them a variable
	local Levelexpdata
	
	local Blacksmithdata
	local Blacksmithexp
	
	local Scythedata
	local Rapierdata
	local Greatsworddata
	local Straightsworddata
	local Daggerdata
	
	local Scytheexpdata
	local Rapierexpdata
	local Greatswordexpdata
	local Straightswordexpdata
	local Daggerexpdata
	
	local s, e = pcall(function()
		Coldata = DataStore:GetAsync(Player.UserId.."-Coldata") or 0 --check if they have data, if not it'll be "0"
		
		Blacksmithdata = DataStore:GetAsync(Player.UserId.."-Blacksmithdata") or 0
		Blacksmithexp = DataStore:GetAsync(Player.UserId.."-Blacksmithexp") or 0
		
		Leveldata = DataStore:GetAsync(Player.UserId.."-Leveldata") or 1--check if they have data, if not it'll be "1"
		Levelexpdata = DataStore:GetAsync(Player.UserId.."-Levelexpdata") or 0
		
		Scythedata = DataStore:GetAsync(Player.UserId.."-Scythedata") or 0
		Rapierdata = DataStore:GetAsync(Player.UserId.."-Rapierdata") or 0
		Greatsworddata = DataStore:GetAsync(Player.UserId.."-Greatsworddata") or 0
		Straightsworddata = DataStore:GetAsync(Player.UserId.."-Straightsworddata") or 0
		Daggerdata = DataStore:GetAsync(Player.UserId.."-Daggerdata") or 0
		
		Scytheexpdata = DataStore:GetAsync(Player.UserId.."-Scytheexpdata") or 0
		Rapierexpdata = DataStore:GetAsync(Player.UserId.."-Rapierexpdata") or 0
		Greatswordexpdata = DataStore:GetAsync(Player.UserId.."-Greatswordexpdata") or 0
		Straightswordexpdata = DataStore:GetAsync(Player.UserId.."-Straightswordexpdata") or 0
		Daggerexpdata = DataStore:GetAsync(Player.UserId.."-Daggerexpdata") or 0
	end)

	if s then
		print("Success")
		Player:WaitForChild("Skills").Blacksmithskill.Value = Blacksmithdata
		Player:WaitForChild("Skills").Blacksmithskill.Exp.Value = Blacksmithexp
		
		Player:WaitForChild("Level").Value = Leveldata --setting data if its success
		Player:WaitForChild("Values").Col.Value = Coldata --setting data if its success
		Player:WaitForChild("Level").Exp.Value = Levelexpdata
		
		Player:WaitForChild("Skills").Swordskills.Rapierskill.Value = Rapierdata
		Player:WaitForChild("Skills").Swordskills.Scytheskill.Value = Scythedata
		Player:WaitForChild("Skills").Swordskills.Greatswordskill.Value = Greatsworddata
		Player:WaitForChild("Skills").Swordskills.Straightswordskill.Value = Straightsworddata
		Player:WaitForChild("Skills").Swordskills.Daggerskill.Value = Daggerdata
		
		Player:WaitForChild("Skills").Swordskills.Daggerskill.Exp.Value = Daggerexpdata
		Player:WaitForChild("Skills").Swordskills.Rapierskill.Exp.Value = Rapierexpdata
		Player:WaitForChild("Skills").Swordskills.Greatswordskill.Exp.Value = Greatswordexpdata
		Player:WaitForChild("Skills").Swordskills.Scytheskill.Exp.Value = Scytheexpdata
		Player:WaitForChild("Skills").Swordskills.Straightswordskill.Exp.Value = Straightswordexpdata
	else
		game:GetService("TestService"):Error(e)  --if not success then we error it to the console
	end

end)

Players.PlayerRemoving:Connect(function(Player)
	local s, e = pcall(function()
		print("Success")
		DataStore:SetAsync(Player.UserId.."-Coldata", Player.Values.Col.Value) --setting data
		
		DataStore:SetAsync(Player.UserId.."-Blacksmithdata", Player.Skills.Blacksmithskill.Value)
		DataStore:SetAsync(Player.UserId.."-Blacksmithexp", Player.Skills.Blacksmithskill.Exp.Value)
		
		DataStore:SetAsync(Player.UserId.."-Leveldata", Player.Level.Value) --setting data
		DataStore:SetAsync(Player.UserId.."-Levelexpdata", Player.Level.Exp.Value)
		
		DataStore:SetAsync(Player.UserId.."-Scythedata", Player.Skills.Swordskills.Scytheskill.Value)
		DataStore:SetAsync(Player.UserId.."-Rapierdata", Player.Skills.Swordskills.Rapierskill.Value)
		DataStore:SetAsync(Player.UserId.."-Greatsworddata", Player.Skills.Swordskills.Greatswordskill.Value)
		DataStore:SetAsync(Player.UserId.."-Straightsworddata", Player.Skills.Swordskills.Straightswordskill.Value)
		DataStore:SetAsync(Player.UserId.."-Daggerdata", Player.Skills.Swordskills.Daggerskill.Value)
		
		DataStore:SetAsync(Player.UserId.."-Daggerexpdata", Player.Skills.Swordskills.Daggerskill.Exp.Value)
		DataStore:SetAsync(Player.UserId.."-Rapierexpdata", Player.Skills.Swordskills.Rapierskill.Exp.Value)
		DataStore:SetAsync(Player.UserId.."-Greatswordexpdata", Player.Skills.Swordskills.Greatswordskill.Exp.Value)
		DataStore:SetAsync(Player.UserId.."-Scytheexpdata", Player.Skills.Swordskills.Scytheskill.Exp.Value)
		DataStore:SetAsync(Player.UserId.."-Straightswordexpdata", Player.Skills.Swordskills.Straightswordskill.Exp.Value)
	end)
	if not s then game:GetService("TestService"):Error(e) end --if not success then error
end)

Edit: It still saves all the data if I rejoin again, but certain times Ill just join the game and all the data will be gone.

1 Like

This is an incredibly inefficient way to call Async for datastores. You are repeatedly requesting these calls, and there is a limit for the amount of time you can call Async operations on a datastore, so you should completely scrap or rewrite this system to return one table with the corresponding data instead of running so many Async calls which is indubitably going to throw.

3 Likes

There is Limits on Async calls. According to this docs page these are limits:

Request Type Functions Requests per Minute
Get GetAsync() 60 + numPlayers Ă— 10
Set (limit is shared among all listed functions) SetAsync()
IncrementAsync()
UpdateAsync()
RemoveAsync() 60 + numPlayers Ă— 10
Get Sorted GetSortedAsync() 5 + numPlayers Ă— 2
Get Version GetVersionAsync() 5 + numPlayers Ă— 2
List ListDataStoresAsync()
ListKeysAsync()
ListVersionAsync() 5 + numPlayers Ă— 2
Remove RemoveVersionAsync() 5 + numPlayers Ă— 2

Figure out how to only use One datastore and save a Table instead of a solo value like:

local list = { [“Cash”] = 100, [“AnotherValue”] = true}

You can save lists and not just a Value like a number! Condense your data in One datastore and One :GetAsync and :SetAsync Call for them

3 Likes