I want to know how you would create a new place for a group of players to teleport to. The best example of this is like in TDS (Tower Defense Simulator), where you go down the elevator and teleport to a new place with only those players in the elevator. I want to do the exact same thing but for my game.
I already know how to use teleport service but it teleports all the players to the same place. I want a new place for every group of players.
You cant get “a new place for every group of players”, what you can do is make a reserved server and then put all the players you want to teleport inside of a table, and just teleport the players from the table to a reserved server. Example code:
local players = {} -- add players to the players table how you want
local placeId = YOUR_PLACE_ID_HERE
local reservedServer = game.TeleportService:ReserveServer(placeId)
game.TeleportServiceTeleportToPrivateServer(placeId, reservedServer, players)
If you want to add the players to the table when they touch a part just do this in the same script above the teleport function but below the players table, example:
local players = {} -- add players to the players table how you want
local placeId = YOUR_PLACE_ID_HERE
local Part = script.Parent -- or the location to the part thats gonna be touched.
Part.Touched:Connect(function(hit)
pcall(function()
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
table.insert(players, plr
end)
end)
task.wait(intermissionTime) -- this can be how long you want to wait until you teleport everyone
local reservedServer = game.TeleportService:ReserveServer(placeId)
game.TeleportServiceTeleportToPrivateServer(placeId, reservedServer, players)
Yes, an example place id: 185655149 (a place id of the default place of an experience)
OR
If you created a new place in the same experience, you would copy that placeID using the roblox studio Asset Manager > Places find the place and right click on it and click on Copy Id
What do you mean it doesnt work? Is it not teleporting or?
Note: You can NOT teleport players inside of roblox studio, so publish the game and test it in real roblox and not in studio. And you can only teleport from a place you own to a place you also own.
Try putting the teleport in a pcall, and wait a couple of seconds so you can load in and actually touch the part.
local players = {}
local placeId = 7951878865
local Part = script.Parent
local TeleportService = game:GetService("TeleportService")
Part.Touched:Connect(function(hit)
pcall(function()
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if (plr:IsA("Player")) then
table.insert(players, plr)
end
end)
end)
task.wait(10)
print("teleporting")
print(players)
pcall(function()
local reservedServer = TeleportService:ReserveServer(placeId)
TeleportService:TeleportToPrivateServer(placeId, reservedServer, players, nil, nil, nil)
end)