Hi, I’ve been trying to make a global matchmaking system recently but teleporting players isn’t working correctly. When they should get teleported, they get an error message instead. It says "Teleport failed due to an unexpected error. (Error Code: 769)
Also on the dev console I got an error like this
(Please don’t mind theese two first ones or the warning either)
And here are the scripts:
PublishAsync
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local addPlayerEvent = game:GetService("ReplicatedStorage").GlobalMatchmaking.AddPlayer
local removePlayerEvent = game:GetService("ReplicatedStorage").GlobalMatchmaking.RemovePlayer
local globalMatchmakingFolder = game:GetService("ServerStorage").GlobalMatchmaking
local maxPlayers = {
Race = 2,
Onevsone = 2,
BossRide = 8
}
local gamemodesPlaceIDs = {
Race = 5940425780
}
addPlayerEvent.OnServerEvent:Connect(function(player, gamemode)
player.Multiplayer.Gamemode.Value = gamemode
local playerQueue = false
for i, v in pairs(globalMatchmakingFolder[gamemode]:GetChildren()) do
if playerQueue == false then
local maxPlayers = maxPlayers[gamemode]
local children = v.Players:GetChildren()
if #children ~= maxPlayers or #children > maxPlayers then
if #children + 1 == maxPlayers then
local code = TeleportService:ReserveServer(gamemodesPlaceIDs[gamemode])
local info = {
Code = code,
PlayerName = player.Name,
PlayerId = player.UserId,
Children = #children,
Gamemode = gamemode,
QueueName = v.Name
}
print(code)
print("code")
local encodedInfo = HttpService:JSONEncode(info) --turns info into a string
MessagingService:PublishAsync("QueueJoin", encodedInfo) --doesn't allow tables in the 2nd parameter
else
local info = {
PlayerName = player.Name,
PlayerId = player.UserId,
Children = #children,
Gamemode = gamemode,
QueueName = v.Name
}
local encodedInfo = HttpService:JSONEncode(info) --turns info into a string
MessagingService:PublishAsync("QueueJoin", encodedInfo) --doesn't allow tables in the 2nd parameter
end
playerQueue = true
end
end
end
if playerQueue == false then
local info = {
PlayerName = player.Name,
PlayerId = player.UserId,
Gamemode = gamemode
}
local encodedInfo = HttpService:JSONEncode(info) --turns info into a string
MessagingService:PublishAsync("QueueCreate", encodedInfo) --doesn't allow tables in the 2nd parameter
end
end)
removePlayerEvent.OnServerEvent:Connect(function(player)
local playersGamemode = player.Multiplayer.Gamemode.Value
local info = {
PlayerName = player.Name,
Gamemode = playersGamemode
}
local encodedInfo = HttpService:JSONEncode(info) --turns info into a string
MessagingService:PublishAsync("QueueRemove", encodedInfo) --doesn't allow tables in the 2nd parameter
end)
Players.PlayerRemoving:Connect(function(player)
local playersGamemode = player.Multiplayer.Gamemode.Value
local info = {
PlayerName = player.Name,
Gamemode = playersGamemode
}
local encodedInfo = HttpService:JSONEncode(info) --turns info into a string
MessagingService:PublishAsync("QueueRemove", encodedInfo) --doesn't allow tables in the 2nd parameter
end)
SubscribeAsync
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local globalMatchmakingFolder = game:GetService("ServerStorage").GlobalMatchmaking
local maxPlayers = {
Race = 5,
Onevsone = 2,
BossRide = 8
}
MessagingService:SubscribeAsync("QueueJoin", function(message)
local info = HttpService:JSONDecode(message.Data) --turns info into a table
local code = info.Code
local playerName = info.PlayerName
local playerId = info.PlayerId
local Children = info.Children
local Gamemode = info.Gamemode
local QueueName = info.QueueName
local playername = Instance.new("StringValue")
playername.Name = "Player"..Children + 1
playername.Value = playerName
playername.Parent = globalMatchmakingFolder[Gamemode]:FindFirstChild(QueueName).Players
local playerid = Instance.new("IntValue")
playerid.Name = "PlayerId"
playerid.Value = playerId
playerid.Parent = playername
local theQueue = globalMatchmakingFolder[Gamemode]:FindFirstChild(QueueName)
for ii, vv in pairs(theQueue.Players:GetChildren()) do
if game.Players:FindFirstChild(vv.Value) then
local player = game.Players:FindFirstChild(vv.Value)
local MultiplayerFrame = player:WaitForChild("PlayerGui"):WaitForChild("MainMenu"):WaitForChild("Multiplayer")
local Queue = MultiplayerFrame:WaitForChild("Queue")
for i, v in pairs(theQueue.Players:GetChildren()) do
local userName = v.Value
local userId = v.PlayerId.Value
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size352x352
local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
Queue.Players[v.Name].Image = content
Queue.Players[v.Name].PlayerNameText.Text = userName
end
end
end
if code ~= nil then
print("Code ~= nil")
for i, v in pairs(theQueue.Players:GetChildren()) do
if Players:FindFirstChild(v.Value) then
local player = Players:FindFirstChild(v.Value)
print(code)
TeleportService:TeleportToPrivateServer(5852131109, code, {player}) -- Actually teleport the players
end
end
end
end)
MessagingService:SubscribeAsync("QueueCreate", function(message)
local info = HttpService:JSONDecode(message.Data) --turns info into a table
local player = info.PlayerName
local playerId = info.PlayerId
local Gamemode = info.Gamemode
local newQueueFolder = Instance.new("Folder")
newQueueFolder.Name = player
newQueueFolder.Parent = globalMatchmakingFolder:FindFirstChild(Gamemode)
local playersInQueue = Instance.new("Folder")
playersInQueue.Name = "Players"
playersInQueue.Parent = newQueueFolder
local playername = Instance.new("StringValue")
playername.Name = "Player1"
playername.Value = player
playername.Parent = playersInQueue
local playerid = Instance.new("IntValue")
playerid.Name = "PlayerId"
playerid.Value = playerId
playerid.Parent = playername
local userId = playerid.Value
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size352x352
local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
if Players:FindFirstChild(playername.Value) then
local Player = Players:FindFirstChild(playername.Value)
local MultiplayerFrame = Player:WaitForChild("PlayerGui"):WaitForChild("MainMenu"):WaitForChild("Multiplayer")
local Queue = MultiplayerFrame:WaitForChild("Queue")
Queue.Players.Player1.Image = content
Queue.Players.Player1.PlayerNameText.Text = playername.Value
end
end)
MessagingService:SubscribeAsync("QueueRemove", function(message)
local info = HttpService:JSONDecode(message.Data) --turns info into a table
local playerName = info.PlayerName
local playersGamemode = info.Gamemode
for i, v in pairs(globalMatchmakingFolder[playersGamemode]:GetChildren()) do
for ii, vv in pairs(v.Players:GetChildren()) do
if vv.Value == playerName then
vv:Destroy()
end
end
if #v.Players:GetChildren() == 0 then
v:Destroy()
end
end
end)
Could someone explain why is it happening?