events.CreateGame.OnServerEvent:Connect(function(player,map)
local mapId = modules.mapIds.mapids[map]
print(map)
print(mapId)
local code = services.TS:ReserveServer(mapId)
-- create a smaller 5 digit code to complement the long access code
local Outcome = {}
for i=1,5,1 do
local count = math.random(1,9)
table.insert(Outcome, count)
end
for i,v in pairs(Outcome) do
if i == 1 then
OutcomeString = v
else
OutcomeString = OutcomeString..v
end
end
local servers = services.MSS:GetSortedMap("servers")
servers:SetAsync(tostring(OutcomeString), code, 2592e+3)
services.TS:TeleportToPrivateServer(mapId,code,{player})
end)
Can’t repro. Wrote my code roughly the same as you but in my own way.
-- game:SetPlaceId(7537264543)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MemoryStoreService = game:GetService("MemoryStoreService")
local TeleportService = game:GetService("TeleportService")
local CreateGameEvent = Instance.new("RemoteEvent")
local CreateGame = CreateGameEvent.OnServerEvent
local function onCreateGameFired(player)
local accessCode = TeleportService:ReserveServer(game.PlaceId)
local codeIndex do
local numbers = table.create(5)
for i = 1, 5 do
table.insert(numbers, math.random(1, 9))
end
codeIndex = table.concat(numbers)
end
local serverCodes = MemoryStoreService:GetSortedMap("ServerCodes")
local success = pcall(serverCodes.SetAsync, serverCodes, codeIndex, accessCode, 2592e+3)
task.delay(1, function()
local getSuccess, serverCode = pcall(serverCodes.GetAsync, serverCodes, codeIndex)
if getSuccess then
print(string.format("Successfully got code! Code index: %s / Access Code: %s", codeIndex, serverCode))
else
warn(string.format("Unsuccessful in fetching code. Code index: %s / Issue: %s", codeIndex, serverCode))
end
local deleteSuccess, exception = pcall(serverCodes.RemoveAsync, serverCodes, codeIndex)
if deleteSuccess then
print(string.format("Successfully removed code! Code index: %s", codeIndex))
else
warn(string.format("Unsuccessful in deleting code. Code index: %s / Issue: %s", codeIndex, exception))
end
end)
print("Successfully called SetAsync on SortedMap?", success)
end
CreateGame:Connect(onCreateGameFired)
CreateGameEvent.Name = "CreateGame"
CreateGameEvent.Parent = ReplicatedStorage
Consider debugging your code a little more and providing some results? Ref: Debugging Tools