I currently have some trouble figuring this out. Im trying to make an invasion system like in the souls games.
Currently how it works, is that when players join the hub place, they get teleported to the main place where the game takes place,
local TeleportService = game:GetService("TeleportService")
local MemoryStoreService = game:GetService("MemoryStoreService")
local serverRegistry = MemoryStoreService:GetSortedMap("ServerRegistry")
function createServer(player, region, avgLevel)
local serverCode = TeleportService:ReserveServer(82655950777128)
TeleportService:TeleportToPrivateServer(82655950777128, serverCode, {player})
end
game.Players.PlayerAdded:Connect(function(player)
createServer(player, nil, 1)
end)
After that, in the main place, i use memory store service to add servers as entries:
function createServer(player, region, avgLevel)
local serverCode = game.PrivateServerId
if not serverCode or serverCode == "" then
serverCode = "TestServer_" .. tostring(game.JobId)
print("Using fallback server code:", serverCode)
end
local serverData = {
code = serverCode,
region = region or "global",
avgLevel = avgLevel or 1,
playerCount = 1
}
print("Saving data with key:", serverCode)
print("Server Data:", serverData)
local success, err = pcall(function()
serverRegistry:SetAsync(serverCode, serverData, 100)
end)
if not success then
warn("Failed to save server data:", err)
end
end
When trying to join a different player though, i get an error: Attempted to teleport to a place that is restricted. (Error code: 773)
function findServer(region, playerLevel)
local allEntries = serverRegistry:GetRangeAsync(0, 100)
local currentServerCode = game.PrivateServerId
for _, entry in ipairs(allEntries) do
local serverData = entry.value
local key = entry.key
print("Checking server with key:", key, "Data:", serverData)
if serverData.code and serverData.code ~= currentServerCode then
print("Current server id:", game.PrivateServerId)
print("Found suitable server:", serverData.code)
return serverData.code
end
end
print("No suitable servers found!")
return nil
end
function joinServer(player, region, playerLevel)
print("Attempting to invade player...")
local serverCode = findServer(region, playerLevel)
if serverCode then
TeleportService:TeleportToPrivateServer(82655950777128, serverCode, {player})
else
end
end
This is the code for finding, and joining servers.
It does find the valid server code, but for some reason it cant join.
I need some help.

