Can't get anything from DataStore

So I’m writing Server Browser codes to store player-owned server information to a DataStore (I don’t want to use spreadsheet or anything external because it might crash if this feature has high traffic). Initially I’m able to get it working and output as expected but next day it’s just suddenly decided not to output anything and instead return nil. I’ve googled all over and all pointed to an exact same code I used.

That is when my code in accessServerDS function get more unnecessarily complex just to get anything out of datastore but all of my efforts went to no avail… This is my code in a server-side script (this is inside screen gui instance);

local DSS = game:GetService("DataStoreService")
local GlobalPrivateServerDS = DSS:GetOrderedDataStore("Global Server IDs") -- used to list every server IDs that are created (also not actual name)
local ServerInfoDS = DSS:GetDataStore("DataStore Name") -- not actual name for this post

-- Access Server Information's DataStore (ServerInfoDS)
function accessServerDS(id)
	local serverData = nil
	local serverDict = {}
	local indexName = {}
	local values = {}
	local success = nil
	local err = nil
	local attempt = 0
	
	repeat
		local success, err = pcall(function()
			serverData = ServerInfoDS:GetAsync(id, options)
		end)
		
		attempt += 1
		
		if not success then 
			warn("Datastore might not found, retrying... ("..attempt.."/3) attempts")
			task.wait(1)
		end
	until success or attempt == 3
	
	if attempt == 3 then
		error("Datastore doesn't exist!")
	end
	
	-- Convert from Datastore structure into dictionary structure
	for i,v in pairs(serverData) do
		table.insert(indexName, i)
		table.insert(values, v)
	end
	
	-- debug purpose
	print(tostring(indexName)) -- outputs "tables: 0xblah blah" with tostring(); cant output without it
	print(tostring(values)) -- outputs "tables: 0xblah blah" with tostring(); cant output without it
	
	-- Merge two dictionaries into a singular dictionary
	serverDict = {
		[indexName[1]] = values[1],
		[indexName[2]] = values[2],
		[indexName[3]] = values[3],
		[indexName[3]] = values[4]
	}
	
	-- debug purpose
	print(serverDict) -- sometimes outputs in normal text without having to use tostring(), otherwise it returns back to "tables: 0xblah blah"
	
	if success then
		print("success?") -- able to output in console
		if serverDict then
			return serverDict -- still return "tables: 0xblah blah" anyways, no matter how hard I try dencrypt it
		else
			return false
		end
	end
end

-- Update, sort, and display a list of all servers
function SortGlobalPrivateSeversAsync()
	local pages = GlobalPrivateServerDS:GetSortedAsync(false, 100)

	for i,v in pairs(script.Parent.Parent.ServerListScrollingFrame:GetChildren()) do
		if v:IsA("Frame") then
			v:Destroy()
		end
	end

	local data = pages:GetCurrentPage()

	for i,v in pairs(data) do
		warn(v.value, v.key)
		task.wait(.2)
		local serverData = accessServerDS(v.key)
		
		if serverData then
			for _, data1 in pairs(serverData) do
				local ServerFrameClone = script.Parent.ServerFrame:Clone()
				ServerFrameClone.Parent = script.Parent.Parent.ServerListScrollingFrame
				ServerFrameClone.Name = v.key
				ServerFrameClone.PlayerCount.Text = #game.Players:GetPlayers().."/32" -- trying to get player counts
				ServerFrameClone.ServerName.Text = data1['ServerName']
				ServerFrameClone.ServerOwner.Text = "Custom | Hosted by: " .. Players:GetNameFromUserIdAsync(data1['ServerOwnerId'])
				ServerFrameClone.ServerCode.Text = "Server Code: " .. data1['JoinCode']
				ServerFrameClone.JoinServer.MouseButton1Click:Connect(function()
					TS:TeleportToPrivateServer(game.PlaceId, data1['ServerAccessCode'], {plr})
				end)
			end
		else
			warn(v.key .. " server ID doesn't exist in datastore!")
		end
	end
end

Does anyone have a better approach to retrieving DataStore reliably without getting weird stuff like “tables: 0xblah blah” consistently such as; “tables: 0x8d8d2b546c630bfe”? I’m trying to get information from DataStore and put them into gui. I’m able to successfully save all of those information into the DataStore, but getting info from DataStore isn’t really successful at all.

Any helps are appreciated!

EDIT: I already put codes that convert from DataStore structures to dictionary structures inside if success then statement, the result is same.

2 Likes

Your data is there. In studio just turn “Show memory address for tables” off.

1 Like

It is off, I think that’s off by default because I never touched that before. It’s just show memory address look like this;
output: tables: 0xblah blah = { datas here I expect to see }

Without memory address look like this;
output: { datas here I expect to see }

But I still see another output that still show memory address regardless. Also I tested them in live game and it still show memory addresses, resulting in failure to get datas and eventually errored my whole script when trying to populate my scrolling gui.

1 Like

You can only view the data in the studio console. In all other places it will just print the memory address.

2 Likes