Help with ordered Datastore - Roblox Scripting Support

Ok, This is the script in the reserved server:

local tp = game:GetService("TeleportService")
local players = game:GetService("Players")

local DataStoreService = game:GetService("DataStoreService")
local PrivateServerCodes = DataStoreService:GetOrderedDataStore("PrivateServerCodes")

game:GetService('ReplicatedStorage').PublishServerCode.OnServerEvent:Connect(function(player, code, Jobid)
	local function printCodePages()
		local isAscending = false
		local pageSize = 100
		local pages = PrivateServerCodes:GetSortedAsync(isAscending, pageSize)
		local CurrentPage = pages:GetCurrentPage()
		for rank, data in ipairs(CurrentPage) do
			local Code = data.key
			local JobId = data.value
			print(Code .. " Is the code, and  " .. JobId .. " Is the JobId ")
		end

		-- Potentially load the next page...
		--pages:AdvanceToNextPageAsync()
	end

	-- Publish the code as the key and the JobId as the value (Which can't be a string)
	PrivateServerCodes:SetAsync(code, Jobid)
	
	printCodePages()
end)

The code:
88639056 (Expected)

The JobId:
e49b0b05-47f8-f0ab-dbc7-1e3090476300 (Also expected)

This is the outcome:

Iā€™m guessing you canā€™t publish the jobID in datastore because itā€™s a string.

If that is the case, then that is a huge problemā€¦ as I need to publish the jobId

Hello? Sorry. Have you got any leads or something lol?

Sorry, I was a bit busy.

Now that Iā€™m back, hereā€™s two ways you can go about this:
1.) JSONEncode
2.) Create a table, with keys perhaps that actually have the keys, and then set the saved value of the index in the table to require the string fromā€¦?

Iā€™m unsure honestly, :sweat_smile:
Iā€™m looking more into some documentation so that I can find a way to help though!

But hereā€™s an example, directly from the documentation that helps serialize to store more data types:
The documentation also provides a little more of an explanation too.

local tab = {
	-- Remember: these lines are equivalent
	["message"] = "success";
	message = "success";
	
	info = {
		points = 123,
		isLeader = true,
		user = {
			id = 12345,
			name = "JohnDoe"
		},
		past_scores = {50, 42, 95},
		best_friend = nil
	}
}
 
local json = HttpService:JSONEncode(tab)
print(json)
1 Like

Thanks, Iā€™ll look into it. Thankyou for all your help.

Of course! Glad to be of assistance. :happy2:

1 Like