I’ve been stuck on this issue for quite a while now and I thought I managed to solve it but sadly I was wrong. I’m currently trying to pass data from a Hub game where the data will go into reserved server with the queued players data. Well whenever I tried to make tables for each player and use their userId as the key, I could never get the data on the other end. When I tried to pass a basic table with mock data, it went through.
---DUMMY CODE----
local part = script.Parent
local CD = script.Parent.ClickDetector
local TS = game:GetService("TeleportService")
local TSO = Instance.new("TeleportOptions")
local ID = 101663535309986
local Players = game:GetService("Players")
local playersToTeleport = {}
local playerData = {}
Players.PlayerAdded:Connect(function(plr)
table.insert(playersToTeleport, plr)
playerData[plr.UserId] = {
Name = plr.Name,
ID = plr.UserId
}
end)
Players.PlayerRemoving:Connect(function(plr)
for i,v in pairs(playersToTeleport) do
if v == plr then
table.remove(playersToTeleport, i)
break
end
end
playerData[plr.UserId] = nil
end)
CD.MouseClick:Connect(function()
local success, errorMessage = pcall(function()
local teleportData = {}
for userId, data in pairs(playerData) do
teleportData[userId] = {
Name = data.Name,
ID = data.ID
}
end
TSO:SetTeleportData(teleportData)
TS:TeleportAsync(ID, playersToTeleport, TSO)
end)
if success then
print("Teleport successful!")
else
warn("Teleport failed: " .. errorMessage)
end
end)
Could you share a simple example of writing data to a MemoryStore queue in one place and retrieving it in another with multiple players data? I’m having trouble retrieving data from MemoryStoreService on the receiving end after passing it from my hub server. I’ve adjusted my hub script to use MemoryStoreService:GetQueue to store player data (UserId, Name, NUMBER) with AddAsync and I think i set it up right. Yet when I try to read it in the sub place I get nothing. Are there common mistakes or am i approaching this the wrong way?
receiving:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Create a RemoteEvent to communicate with clients
local TeleportDataEvent = ReplicatedStorage:FindFirstChild("TeleportDataEvent") or Instance.new("RemoteEvent")
TeleportDataEvent.Name = "TeleportDataEvent"
TeleportDataEvent.Parent = ReplicatedStorage
--Allows Client to request for their data
TeleportDataEvent.OnServerEvent:Connect(function(player, teleportData)
if teleportData and teleportData[player.UserId] then
local data = teleportData[player.UserId]
print("Received data for " .. player.Name .. ":")
print("Name: " .. (data.Name or "N/A"))
print("ID: " .. (data.ID or "N/A"))
print("NUMBER: " .. (data.NUMBER or 0))
-- Set up leaderstats or game state
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local num = Instance.new("IntValue")
num.Name = "NUMBER"
num.Value = data.NUMBER or 0
num.Parent = leaderstats
leaderstats.Parent = player
else
warn("No valid teleport data for " .. player.Name)
end
end)
hub:
---DUMMY CODE----
local part = script.Parent
local CD = script.Parent.ClickDetector
local TS = game:GetService("TeleportService")
local TSO = Instance.new("TeleportOptions")
local ID = 101663535309986
local Players = game:GetService("Players")
local MemoryStoreService = game:GetService("MemoryStoreService")
local queue = MemoryStoreService:GetQueue("TeleportQueue")
local playersInQueue = {}
local playersToTeleport = {}
local playerData = {}
Players.PlayerAdded:Connect(function(plr)
table.insert(playersToTeleport, plr)
playerData[plr.UserId] = {
Name = plr.Name,
ID = plr.UserId,
NUMBER = 30
}
end)
Players.PlayerRemoving:Connect(function(plr)
--clear queue
playerData[plr.UserId] = nil
playersInQueue[plr.UserId] = nil
end)
CD.MouseClick:Connect(function(plrWhoClicked)
local success, errorMessage = pcall(function()
queue:AddAsync({
UserId = plrWhoClicked.UserId,
Data = playerData[plrWhoClicked.UserId]
}, 3600, plrWhoClicked.UserId)
playersInQueue[plrWhoClicked.UserId] = true
print(plrWhoClicked.Name .. " was added to the queue")
end)
if not success then
warn("Failed to add ".. plrWhoClicked.Name .. " to queue")
end
end)
local function processQueue()
local success, result = pcall(function()
return queue:ReadAsync(1, 5, true)
end)
if success and result and #result >= 1 then
local playersToTeleport = {}
local teleportData = {}
for _, item in ipairs(result) do
local player = Players:GetPlayerByUserId(item.UserId)
if player then
table.insert(playersToTeleport, player)
teleportData[item.UserId] = item.Data
end
end
if #playersToTeleport >= 1 then
TSO.ShouldReserveServer = true
TSO:SetTeleportData(teleportData)
local success, teleportResult = pcall(function()
return TS:TeleportAsync(ID, playersToTeleport, TSO)
end)
if success then
print("Teleported " .. #playersToTeleport .. " players")
local removeSuccess, removeError = pcall(function()
queue:RemoveAsync()
end)
if not removeSuccess then
warn("Failed to remove players from queue: " .. removeError)
end
for _, player in ipairs(playersToTeleport) do
playersInQueue[player.UserId] = nil
end
else
warn("Teleport failed: " .. teleportResult)
end
else
print("Not enough valid players in queue")
end
elseif not success then
warn("Failed to read queue: " .. (result or "Unknown error"))
end
end
while true do
processQueue()
task.wait(10)
end
Bumping, Still having this issue. I’ve looked in the MemoryStoreService and to my understanding it just a temp data holder. Now my question is what difference would this make from what I had before. Where before I made a table/dictionary and then used the UserId as the key then pass the table as data to the sub place. So if I add the MemoryStoreService, Am I not just adding another step? With memory, it’ll need a temp database or whatever then pass the queue table data right?