So, the perfectly working code below (as of now), will send people to a private server. (There is more code that is unrelated, but changes the group properties)
local f = workspace:WaitForChild("Matchmaking")
local info = require(script.Settings)
local tp = game:GetService("TeleportService")
-- Function to create a private server and teleport players to it
local function createAndTeleportToPrivateServer(players,main,current)
local host = game.Players:FindFirstChild(main)
local reservedServerCode = tp:ReserveServer(14123061693)
if not reservedServerCode then
warn("Failed to reserve a private server.")
end
local success, errorMessage = tp:TeleportAsync(reservedServerCode, players)
if success then
print("Teleported players to the private server.")
else
warn("Failed to teleport players to the private server:", errorMessage)
end
end
-- Define the "Group" class
local Group = {
currentPlayers = 0,
difficulty = "",
gamemode = "",
plrs = {},
modifier = ""
}
-- Constructor for the "Group" class
function Group.new(players, difficulty, gamemode,modifier)
local self = setmetatable({}, { __index = Group })
-- Initialize properties
self.currentPlayers = players or 0
self.difficulty = difficulty or ""
self.gamemode = gamemode or ""
self.plrs = {}
self.modifier = modifier
return self
end
-- Methods for the "Group" class
function Group:addPlayer(name)
self.currentPlayers = self.currentPlayers + 1
table.insert(self.plrs, name)
end
function Group:removePlayer(name)
self.currentPlayers = self.currentPlayers - 1
local new = {}
for i, v in pairs(self.plrs) do
if v ~= name then
table.insert(new,v)
end
end
self.plrs = new
end
function Group:setDifficulty(difficulty)
self.difficulty = difficulty
end
function Group:setGamemode(gamemode)
self.gamemode = gamemode
end
function Group:setModifier(m)
self.modifier = m
end
function Group:getPlayers()
return self.currentPlayers
end
function Group:getDifficulty()
return self.difficulty
end
function Group:getGamemode()
return self.gamemode
end
function Group:getModifier()
return self.modifier
end
function Group:getAll()
return self.plrs
end
function Group:FindPlayer(name)
for i, v in self.plrs do
if v == name then
return false
end
end
return true
end
I would like in this code, to be able to send the matchmaking data to the reserved server.