Problem With DataStore (With Tables)

So I’m testing the DataStore with Tables and It doesn’t save, the BIG problem is that I don’t find where’s the problem in the code. So I’ll be pretty grateful with you all if you can help me fix this! :smile: :smile: :smile:

Here’s the code:

DataStoreWithTables3

What is the error? Which code line states the error? Please be more descriptive.

The first problem I see is that you have two variables named data, you should never name two sensitive data with the same name.

Your code seems fine, you should try and test it in a real game.

1 Like

As @ItzMeZeus_IGotHacked said, you should save your changes and try playing the physical game. You can’t test datastore in Roblox Studio.

You are not using the pcall correctly.
Example of what is should look like:

       local success2, currentDucks = pcall(function()
			return DatastoreDucks:GetAsync(Player.UserId.."-leaderstats")
		end)
		
		if success2 then
			task.spawn(createDucks, Player, currentDucks) 
		else
			Player.PlayerGui:FindFirstChild("ErrorFrame").Visible = true
			return
		end

The second arg is the value/table.

Not entirely accurate. While yes they are using such incorrectly, pcall returns a result which can either be whatever is returned from the function that is pcalled, or the error message. If success is false, it returns the error object, otherwise if true returns whatever you return from the function. They are able to use the error object if success returns false as well.

1 Like

Still, it takes up more space. There is no point in making variables that you aren’t going to use.

There are no additional variables. currentDucks in your example would contain the error if success2 is false. If you simply name it something like ‘result’ you can use it for either case.

It wouldn’t error since I have a else statement and at the top I have it wrapped in a pcall.

I think you’re misunderstanding.

local function f(val)
	return val and 'foo' or error('an error occurred')
end

local success, result = pcall(f, true)
print(success, result) -- true, foo

local success2, result2 = pcall(f, false)
print(success2, result2) -- false, an error occurred

result in this case is interchangeable for either what is returned from function f, or if an error occurred, then you’ll receive the error message.

1 Like

I am not good with datastores, this is why I don’t use datastore2.

Test in a normal game, not in studio. I also have problems in studio with DataStore Loading and saving.

1 Like

Do you have CloseToBind or BindToClose?