How to make a Strong DataStore

How would I do use the error functions?

You should check if the function is successful, and if not, retry until it succeeds.

Here is a post about pcalls:

1 Like

Well first of all i recommend using profileservice module it handles everything i described and its free. For your question, check this article Pcalls - When and how to use them - Resources / Community Tutorials - Roblox Developer Forum it also has a example for datastores

What is the profile service module?

Okay Thanks! I am only changing my datastore because I keep losing information.

ProfileService is a module that loads and saves data. Here is a post about ProfileService:

Here you go



Not sure if it does not work anymore, but may be because I leave too quickly.

I dont understand what do you mean you just gave me images

I bought some tools but they did not even save. I have a folder named ToolSaved in Replicated Storage. This may be because it is too quick to save but I am not sure.

local DataStore = game:GetService("DataStoreService"):GetDataStore("MyDataStore")

game.Players.PlayerAdded:Connect(function(plr)




	local data

	local success, errorMessage = pcall(function()
		data = DataStore:GetAsync(plr.UserId)
	end)
	if data ~= nil then
		for _, toolName in pairs(data) do

			local tool = game.ReplicatedStorage.ToolsSaved:FindFirstChild(toolName)

			if tool then
				local newTool = tool:Clone()
				newTool.Parent = plr.Backpack

				local newTool = tool:Clone()
				newTool.Parent = plr.StarterGear

			end
		end
	end	
end)
game.Players.PlayerRemoving:Connect(function(plr)

	local toolsTable = {}

	for _, tool in pairs(plr.Backpack:GetChildren()) do
		if game.ReplicatedStorage.ToolsSaved:FindFirstChild(tool.Name) then
			table.insert(toolsTable,tool.Name)
		end
	end


	local success, errorMessage = pcall(function()
		DataStore:SetAsync(plr.UserId,toolsTable)
	end)

end)

game:BindToClose(function()
	for _, plr in pairs(game.Players:GetPlayers()) do
		local toolsTable = {}

		for _, tool in pairs(plr.Backpack:GetChildren()) do
			if game.ReplicatedStorage.ToolsSaved:FindFirstChild(tool.Name) then
				table.insert(toolsTable,tool.Name)
			end
		end


		local success, errorMessage = pcall(function()
			DataStore:SetAsync(plr.UserId,toolsTable)
		end)	
	end
end)

image

local data

local success, errorMessage = pcall(function()
	data = DataStore:SetAsync(plr.UserId)
end)

This code is making the error, its pretty self explanitory. Also you are using pcall’s without handling the outcome you should read the article i gave you fully and dont rush and paste writing code like you did here it creates really silly errors

Isn’t that correct? I looked at the article and it makes sense.

yes, its correct but you are doing nothing with the result you can do like if not success then handle the error

edit: what i would do here is use discord webhooks to alert me the issue with the data so i can recover their data manually if required.

That is incorrect, you should be using DataStore:GetAsync() for getting data.

Also, Discord webhooks are not for logging.

Thats the code from the OP, not me. I just gave the code and said “this code is making the error, its pretty self explanitory.” you should read my full post before saying its incorrect

Okay I am confused. So the data is not loading that is why it is not working?

@takticiadam You said it was correct here:


@InquistorWasBanned It is not working because the data is not loading.

Oh okay, so how do I load the data?

I think you didnt understand what I meant there, first of all why would you except me to say its incorrect then say its correct out of nowhere, what I meant there is OP is using pcall’s without handling the outcome.

Well change it to :GetAsync, thats it.