I’ve made a script that teleports players into a private server to do wars with each other if they’re in the group. BUT, I’m not sure if it’ll teleport the players into the same server
local TS = game:GetService("TeleportService")
game.Players.PlayerAdded:Connect(function(plr)
if plr:IsInGroup(35025543) then
local success,err = pcall(function()
local code = TS:ReserveServer(game.PlaceId)
TS:TeleportToPrivateServer(game.PlaceId,code,{plr})
end)
if not success then
warn("couldnt tp into war server")
end
end
end)
I don’t think this will teleport players to the same server for every .PlayerAdded event fired and condition checked, since :ReserveServer() returns a unique access code to a private server.
If you want both players to teleport to the same server, I would suggest creating a “battle” requesting system so any player could send a request to another player to teleport to a private server.
You would then pass some sort of table data {player1, player2} to the server via a RemoteEvent or RemoteFunction which reserves a server, then simply use the :TeleportToPrivateServer() method that passes in table data of those two players.
So I should fire a RemoteEvent with the server and players in the parameters? Sorry I’m not good when it comes to reserving servers this is my first time.
-- In a local script,
RemoteEvent:FireServer(TargetPlayer.Name) -- Will send the target players' name (the person you want to battle with) to the server.
-- ^^ You should check if the player is in your group before firing.
-- In a server script,
local TP = game:GetService("TeleportService")
local placeId = game.PlaceId
RemoteEvent.OnServerEvent:Connect(function(player: Player, targetPlayer: Player) -- The 'player' variable is the FIRST argument passed into .OnServerEvent events, followed by any argument you passed after that. In this case, the target player.
local succ, err = pcall(function()
local code = TP:ReserveServer(placeId)
TP:TeleportToPrivateServer(placeId, code, {player, targetPlayer}) -- Will send both players to that private server at once.
end)
-- Basic error logic
if err then
warn("ERROR WHILE TELEPORTING: " .. err)
end
end)
^ Something like this.
Since I’m talking about a player-to-player requesting system, you’ll need to use some sort of ScreenGui along with a TextButton and TextInputBox.
The TextButton will fire the remote event when the player clicks it.
The TextInputBox will verify the target players’ name in case the player made a typo.
Once the TextButton is clicked, and the TextInputBox verified the players’ name, then the RemoteEvent will fire, which the .OnServerEvent event will pick up.