External Database Issues

Hello, I have a game with over 200+ current players however, I noticed some of my player database fails to save and ends up resetting, and it’s a huge issue on my end without knowing what the cause is.

I’ve looked into the DevForum to find possible solutions however these do not work affectively. I’ve tried aswell reattempting every second to save the data to the external database, but it seems to still have issues in the longside.

By chance, is there any way to overcome this, I’m not asking for a script or anything but rather information to maybe fix this issue.

I’m using firebase’s real-time database to save player data.

The Module Includes the following below:


ModuleScript

function DataStoreModule:SetAsync(UserId: {[string]: "Number"}, UserData : {[string]: "TableContent"})
	if(DataBasesModule.GlobalDatabase) then
		local AttemptSuccessful = false;
		local AttemptSettings = {
			["Attempts"] = 0,
			["AttemptsMax"] = 5
		};
		
		local Success, ErrorMessage = pcall(function()
			DataBasesModule.GlobalDatabase:GetAsync(UserId, game:GetService("HttpService"):JSONEncode(UserData));
		end);
		
		if not(Success) then
			repeat task.wait()
				local Success, ErrorMessage = pcall(function()
					DataBasesModule.GlobalDatabase:SetAsync(UserId, game:GetService("HttpService"):JSONEncode(UserData))
				end);
				AttemptSettings.Attempts +=1

				if(Success) then
					AttemptSuccessful = true;
				end
				task.wait(1)
			until (AttemptSuccessful ~= false or AttemptSettings.Attempts >= AttemptSettings.AttemptsMax);
		end
		
		if(AttemptSuccessful ~= false) then
			return {
				["Success"] = true
			};
		else
			local Success, ErrorMessage = pcall(function()
				DataStore:SetAsync("StoredDatabase:"..UserId, UserData)
			end);
			if(Success) then
				return {
					["Success"] = true
				};
			end
		end
	end
	
	return {
		["Success"] = false;
	};
end

function DataStoreModule:GetAsync(UserId : {[string]: "Number"})
	if(DataBasesModule.GlobalDatabase) then
		local DataStoreRequest;
		
		local AttemptSuccessful = false;
		local AttemptSettings = {
			["Attempts"] = 0,
			["AttemptsMax"] = 5
		};
		
		local Success, ErrorMessage = pcall(function()
			DataStoreRequest = DataBasesModule.GlobalDatabase:GetAsync(UserId)
		end);
		
		if not(Success) then
			repeat task.wait()
				local Success, ErrorMessage = pcall(function()
					DataStoreRequest = DataBasesModule.GlobalDatabase:GetAsync(UserId)
				end);
				AttemptSettings.Attempts +=1

				if(Success and DataStoreRequest) then
					AttemptSuccessful = true;
				end
				task.wait(1)
			until (AttemptSuccessful ~= false or AttemptSettings.Attempts >= AttemptSettings.AttemptsMax);
		else
			AttemptSuccessful = true;
		end

		if(AttemptSuccessful ~= false and DataStoreRequest ~= nil) then
			local JSONDecoded = HttpServiceModule:JSONDecode(DataStoreRequest);
			if(JSONDecoded.Success) then
				return {
					["Success"] = true,
					["Response"] = JSONDecoded.Response
				};
			end
		else
			local Success, ErrorMessage = pcall(function()
				DataStoreRequest = DataStore:GetAsync("StoredDatabase:"..UserId);
			end);
			
			if(Success and DataStoreRequest) then
				return {
					["Success"] = true,
					["Response"] = DataStoreRequest
				};
			end
		end
	end
	
	return {
		["Success"] = false;
	};
end

For the reason of why I use ROBLOX’s datastore is just for safety incase it won’t save on the external database. But that’s the issue I want to resolve efficiently.

If you need to see the HTTP Requests I can show the script.

I’d atleast like to know if there’s something similar to my issue that may fix it or atleast anything that could potentially resolve my issue by maybe redoing the code?