About Memory Store Service

Hello Roblox Developers,

I was in the middle of implementing a TeleportService | Roblox Creator Documentation into my game. Where players get to select a level, populated into a group of players, and once the limit is reached, get teleported into another place.

I was going to use TeleportOptions | Roblox Creator Documentation to transfer the data of the level the players has selected, seems like it’s an okay idea because any changes on the client side wouldn’t do much since the server still checks for the correct level and send that instead. But it’s sort of a hacky way? Because the level is being sent multiple times for little reason (teleport options for each player), since it only need to capture once to populate the level on the other place.

Then I came across Memory Stores | Roblox Creator Documentation, something new that seems like a better solution for this purpose, since I only need to store 1 level name and retrieve it on the other place and remove it after. And I don’t think it’s necessary to use Data Store for this (not experienced in it). But I’m having a hard time understanding the documentation since there is no sample code snippets for different use cases.

How does one actually use it? I tried some on my own below.

  • So my understanding, is that I should add the levelName into a queue, read the levelName on the other place through ReadAsync, populate the level, then remove it from queue. Is this correct?
  • How do we identify which group of players belongs to which level? I tried AddAsync(table) but it says can’t convert to Json error. So I supposed we can’t add table into it.
  • Hmm, or I should use sorted map instead? With key value pairs? Generate a key from the player group, then insert the levelName as the value. So it’ll be like the below in theory, but after teleported, how would we go about retrieving the correct key for the correct group?
--// Sample table
-- Key     |     Value
"1qweo210" |     "Level 1"
"2130asd2" |     "Level 2"

Any insight is appreciated!

--// Server script sample test
-- [[ Services ]]
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MemoryStoreService = game:GetService("MemoryStoreService")

-- [[ Modules ]]
local Module_Teleport = require(ReplicatedStorage.Modules:WaitForChild("TeleportModule"))

-- [[ Functions ]]
local function TeleportGroup(finalGroup, levelName)
	--// Prior script above that groups player
	--// Teleport players if group full
	warn("Teleporting players, group is full")
	local Queue = MemoryStoreService:GetQueue("Map", 5)
	Queue:AddAsync(levelName, 5)
		
	local Data, Id = Queue:ReadAsync(10, false, 0)
	print(Data)
	Queue:RemoveAsync(Id)
	--local teleportOptions = Instance.new("TeleportOptions")
	--local teleportResult = TeleportModule.teleportWithRetry(targetPlaceID, finalGroup, levelName)
end