ello, fellow devleopers!
once again im struggling ![]()
so basically im trying to make a system where its like, you click a button, it fires a remote event where the server checks if there is an existing server of the place they are trying to create. if not, create a server.
the system works, but sometimes after a little time goes by, players keep getting put into newly created servers apart from everyone else.
heres the server system:
local TeleportService = game:GetService("TeleportService")
local MemoryStoreService = game:GetService("MemoryStoreService")
local Players = game:GetService("Players")
local sourcePlaceId = 86808605313215
local teleportKeyPrefix = "stadium_"
local store = MemoryStoreService:GetSortedMap("StadiumServers")
local teleportEvent = game.ReplicatedStorage.GameAssets.Events.TP
function getOrCreateServer(stadiumId)
local key = teleportKeyPrefix .. stadiumId
local code = store:GetAsync(key)
if code then
print("Found existing server", stadiumId)
return code
end
print("Creating new server for", stadiumId)
code = TeleportService:ReserveServer(sourcePlaceId)
store:SetAsync(key, code, 3500)
return code
end
teleportEvent.OnServerEvent:Connect(function(player, stadiumId)
if typeof(stadiumId) ~= "string" then
warn("Invalid stadiumId:", stadiumId)
return
end
local success, result = pcall(function()
return getOrCreateServer(stadiumId)
end)
--if success and result then
if success and typeof(result) == "string" then
print("Teleporting")
TeleportService:TeleportToPrivateServer(
sourcePlaceId,
result,
{player},
nil,
{stadium = stadiumId}
)
else
warn("Teleport failed", result)
end
end)
its confusing idk what to do, if my other scripts that activate this are needed i’ll gladly provide them. lmk if any visible issues please!