So my goal is to make a main menu gui where players can click different “Rooms” and then be put in that room to be eventually teleported into the main game after 45 seconds, but I have no idea how to do this, I want all players that was in that room to be in the same game and I’m sure teleporting them all to a private server is how I should do this, but I don’t know how. Could someone point me in the right direction?
Hey there maybe this would help you:
https://developer.roblox.com/en-us/api-reference/function/TeleportService/TeleportPartyAsync
Thanks for the reply, that helped me get a bit more of understanding, but I need to teleport the table of players to a reserved server.
You can use this for Teleporting Groups of players to reserved servers. Here is exactly what it says:
- Teleport any number of Players to a Reserved Server
Loop through the table and teleport the players
Here is an example script that would teleport everyone in the server:
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local placeId = 0 -- replace
local playerList = Players:GetPlayers()
local success, result = pcall(function()
return TeleportService:TeleportPartyAsync(placeId, playerList)
end)
if success then
local jobId = result
print("Players teleported to "..jobId)
else
warn(result)
end
so if someone clicks the gui button to enter one of the rooms how could I insert them into a table then teleport that table to the reserved server?
Alrighty so basically when ever someone creates a new room add it to a rooms table:
Local Script In The Create Room Button
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.CreateRoom:FireServer("Name of the room here")
end)
Server Script In ServerScriptService
local rooms = {}
game.ReplicatedStorage.CreateRoom.OnServerEvent:Connect(function(player, roomName)
rooms[roomName.."_by_"..player.UserId] = {
players={
player.UserId
}
}
end)
Next step:
When you click a play button, teleport the players:
Local Script In Start Room Button
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.StartRoom:FireSever(roomName)
end)
Same server script as before
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local placeId = 0 -- replace
game.ReplicatedStorage.StartRoom.OnServerEvent:Connect(function(player, roomName)
local room = rooms[roomName.."_by_"..player.UserId]
if room then
local playerList = room.players
local success, result = pcall(function()
return TeleportService:TeleportPartyAsync(placeId, playerList)
end)
if success then
local jobId = result
print("Players teleported to "..jobId)
else
warn(result)
end
end
end)
Note: I am on mobile am there might be errors
Ok so I accidently explained it a bit wrong, let me clarify my main goal one more time (And also I think you for you response so much)
So here players can chose the rooms they want to enter out of the those 3, then they will be put inside a table for later.
Then here is basically just a waiting screen until the time runs down and it starts, once the time goes down the players that were entered into that table will be teleported into a reserved server for the main game, if players click the leave button they can be out of that table so they wont be teleported.
I hope this makes sense!
(Also I thought of a couple ways to go about this if would would like me to explain the ways ive tried.)
Ok well in this case some parts can be removed. Here’s some edits:
This could be removed.
This can get reduced to simply:
local rooms = {
Room1 = {
players={}
},
Room2 = {
players={}
},
Room3 = {
players={}
}
}
Then,
Instead of this just fire the remote event when the timer is up.
This can be very similar:
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local placeId = 0 -- replace
game.ReplicatedStorage.StartRoom.OnServerEvent:Connect(function(player, roomName)
local room = rooms[roomName]
if #room.players > 0 then
local playerList = room.players
local success, result = pcall(function()
return TeleportService:TeleportPartyAsync(placeId, playerList)
end)
if success then
local jobId = result
print("Players teleported to "..jobId)
else
warn(result)
end
end
end)
I will give this a try, thank you.
Also something I forgot in both version of the script,
The join button.
local script in the join room button
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.JoinRoom:FireServer("roomName")
end)
Same sever script yet again
game.ReplicatedStorage.JoinRoom.OnServerEvent:Connect(function(player,roomName)
table.insert(rooms[roomName].players, player.UserId)
end)
This is what I have in serverScriptService
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local placeId = 9500853800 -- replace
local rooms = {
Room1 = {
players={}
},
Room2 = {
players={}
},
Room3 = {
players={}
}
}
game.ReplicatedStorage.StartRoom.OnServerEvent:Connect(function(player, roomName)
local room = rooms[roomName]
if #room.players > 0 then
local playerList = room.players
local success, result = pcall(function()
return TeleportService:TeleportPartyAsync(placeId, playerList)
end)
if success then
local jobId = result
print("Players teleported to "..jobId)
else
warn(result)
end
end
end)
game.ReplicatedStorage.JoinRoom.OnServerEvent:Connect(function(player,roomName)
table.insert(rooms[roomName].players, player.UserId)
end)
I am getting an error that says, " 14:43:29.487 ServerScriptService.Teleport:19: attempt to index nil with ‘players’ - Server - Teleport:19 "
What are you passing in as the room name? In the staring local script
“room1”
(Character limit noiuahgoiasdbgisdaubgi)
Well there’s your problem, in the rooms table we named it Room1
not room1
capitalization error. Make sure to make it a capital R
Its the same error, did I do this part of the script right?
This is the script for when the time runs down it triggers the remote event
while true do
wait (1)
if script.Parent.StartTime.Value <= 0 then
game.ReplicatedStorage.StartRoom:FireServer(Room1)
end
end
You need to pass it through as a string so:
local timer = script.Parent.StartTime
timer.Changed:Connect(function()
if not timer.Value == 0 then return end
game.replicatedstorage.startroom:FireServer("Room1")
end)
Also using .Changed is much better than a while loop for performance
Ok that worked, now I misplaced this function, should it be in the main ServerScript used to teleport players?
game.ReplicatedStorage.JoinRoom.OnServerEvent:Connect(function(player,roomName)
table.insert(rooms[roomName].players, player.UserId)
print(player.Name.." joined "..roomName..".")
end)
Yes this should be in the same server script!
Also make sure you have all the remote events and names correctly in ReplicatedStorage