Database does not spit out any table

I am currently in the process of setting up a compact feedback system where you can send a message to the developers via DataStore. However, when retrieving the messages (table), no table is found, although it was saved as such.

Here is an excerpt from the currently still complete datastore:
image

And here is the code that is triggered after the player is joined:

-- Load unreaded feedback
function loadDataStore(player)
	if player then
		local success, errorMessage = pcall(function()
            -- data_key = "reports" (see image)
			load_list = data_get:GetAsync(data_key)
		end)
		if success and load_list then
			task.wait()
			for a,b in pairs(load_list) do
				if type(a) == "table" then
					if a == tostring("uid-"..player.UserId) then
						loadEvent:FireClient(player,b)
						loadDataStore2(player)
                       -- load second kind of feedback (not the problem here)
					end
				else
					warn("Error (Code 4): Table not found")
				end
			end
		end
		if not success then
			warn("Error (Code 2): "..errorMessage)
		end
	end
end

The weird thing is that it had worked before without me changing anything.

Hello, can you send a screenshot of the console to help me see what is wrong?
In case if you don’t know how to open the console, here is how :


I know, otherwise I would have included it, but the thing is, I don’t get an error or anything else. The only thing I get is warn("Error (Code 4): Table not found")

Ok, I see what’s wrong in your script, you just made a small error in the for loop.

a is the key of one of the item of the reports dictionary and b is the value of the key a.
To make it simpler :

print(a) -- "uid-631470404"
print(reports[a]) -- same value as b (which is {id=631470404,message="dies in ein test",time="December 1, 2023})

As you see, a was always a string, so it was never a table and this is why there is an error.
You just need to replace a by b in the “if” condition like that:

if type(b) == "table" then

I hope you understand, if not, don’t hesitate to tell me…

EDIT : To make sure you understand, here is a thing that you need to know:
As I said earlier :

print(a) -- "uid-631470404"
print(reports[a]) -- same value as b (which is {id=631470404,message="dies in ein test",time="December 1, 2023})
--But also :
print(reports[a]["id"]) -- 631470404 (don't forget the quotes)

lol my mistake. yeah a is the key and b is the value, but i thought you could only get it via the key. But thanks, learned something again and maybe for the others here too.

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