Hello. I’m making a studio for a spinoff of 2005 Roblox named “Dino Studio” (Dino studio - Roblox). I need help with servers and joining games. Currently, when you join somebody’s game it reserves a new server but I need to find out how to make it so if there’s an already existing server it joins that (or if there’s just a better method). I’ve tried many options such as saving the JobId on a MemoryStore but it wouldn’t work. Any help would be appreciated
Server code on joining -
local teleportService = game:GetService("TeleportService")
local memory = game:GetService("MemoryStoreService")
game.ReplicatedStorage.Join.OnServerEvent:Connect(function(plr, gameid)
gameid = game.Players:GetUserIdFromNameAsync(gameid) or 1
local data = teleportService:ReserveServer(118633091946519)
--local teleportOptions = Instance.new("TeleportOptions")
--teleportOptions:SetTeleportData(tostring(gameid))
--teleportOptions.ShouldReserveServer = true
--teleportOptions.ReservedServerAccessCode = data
teleportService:TeleportToPrivateServer(118633091946519, data, {plr}, gameid, {tostring(gameid)})
end)
game.ReplicatedStorage.Edit.OnServerEvent:Connect(function(plr)
teleportService:TeleportAsync(113076132254847, {plr})
end)
I have a similar thing that uses reserved servers and yes it seems like everything is good, but you need to save it via memory store. Here’s what I did in my game:
game.ReplicatedStorage.ServerForSpecificWeapon.OnServerEvent:Connect(function(plr, weaponName)
local s, existingServer = pcall(serverTypeMap.GetAsync, weaponTypeMap, weaponName)
if not s then warn(existingServer) return end
local teleportOptions = Instance.new('TeleportOptions')
if existingServer then
teleportOptions.ReservedServerAccessCode = existingServer
else
teleportOptions.ShouldReserveServer = true
end
local result = teleportService:TeleportAsync(game.PlaceId, {plr}, teleportOptions)
if not existingServer then
local s, e
while not s do
s, e = pcall(weaponTypeMap.SetAsync, weaponTypeMap, weaponName, result.ReservedServerAccessCode, 12*60*60)
if not s then warn(e) end
end
s = false
while not s do
s, e = pcall(serverTypeMap.SetAsync, serverTypeMap, result.PrivateServerId, {weaponName, result.ReservedServerAccessCode}, 12*60*60)
if not s then warn(e) end
end
end
end)
It simply saves it to a memory store and retrieves it later.