How do I Teleport All players in the server to another game?

I got an update for you!

I think I found the solution. Turns out my code in studio wasn’t working either, but I changed it up to this and it works like a charm now. Obviously you cannot teleport between places in studio, so it would error. This script should work 100%.

local gameId = 6331956095

for i, Player in pairs(game.Players:GetPlayers()) do
	if Player:IsA("Player") then
		game:GetService("TeleportService"):Teleport(gameId, Player)
	end
end

Let me know if it still doesn’t work, because if it doesn’t it’s definitely something happening with your if statements (if you have any)

2 Likes

Would this be in the server or client? I just wanted to make sure before doing it.

If you make a local script, it will only teleport that one player. In order to teleport everyone in the game, it must be a server script. Local Scripts can only affect the singular player unless a RemoteEvent is used.

1 Like

Ok noted. I’ll try it out as soon as I can. Thanks!

1 Like

Depends on what you’re going to use Teleport Service for.
To teleport all players, it must be a Server Script.
To teleport a client, it must be a Local Script.

1 Like

Void did a better explanation than me.

1 Like

No worries! Every comment helps!

So I tried your code and added a wait(0.5) at the end of the loop to hopefully unclog the queue but it still didn’t work. I an very sorry about this.

How many people are you attempting to teleport? Are they teleporting to a game that is inside the same game? (Place-In-Place, also known as “Universe”)?

Also just a question, but what does the rest of your code look like for getting all players to teleport? You mentioned you only needed help on this one specific section but there could be a possibility something else in the script is causing an issue. I’ll do some more digging while you answer these questions.

1 Like

I’m currently trying to teleport two players (me and my alt). I’m not trying to teleport to a sub game (I know that’s not what it’s called but that’s just what I call it). And the entire thing is made up of a group of scrips going back and fourth from server to client using remote events.

Do you know if these scripts are being fired more than once by accident? You stated TeleportService was getting bottled up with queued requests, when TeleportService can actually take a bit of people

1 Like

I have the first script in the sequence on a debounce.

EDIT: Now that I’m looking at it the debounce does reactivate. let me try making it does not reactivate and get back to you.

EDIT: I tried that and it didn’t work.

Alright.

I also did a test of my script with not just 1 player, but 8 players on a local test server.

I got the error for not teleporting in studio on all the clients, meaning it did attempt to teleport them all, but that’s not possible in studio itself. That’s why I feel as if theres an issue on your end. TeleportService could be acting up, It never is usually the fasting thing on the planet but it does get the job done.

edit There’s 2 errors cuz I added a yield at the beginning when the server started, then tried to teleport again using the command line in studio, both of which attempted to teleport all clients

1 Like

Have you tried it in a real client? That’s what I’m doing.

If you want me to I can send pics and vids of what I’m doing.

I don’t got enough people for testing in a real client. Studio is basically just the roblox client, only without the actual teleport. If the teleport queue is filling up quick, then something might not be right with the debounce or the way you’re firing to the server

believe it or not, the same player who was already instructed to teleport from a script can be added to the queue again a second time, which is kinda dumb.

1 Like

Do you want me to send pictures and videos?

1 Like

Yes, sending pictures + videos of your process is probably the best way to eliminate this issue.

1 Like

robloxapp-20210709-1556056.wmv (3.2 MB)
Please Watch the video first

Script #1 The Trigger

Script #2 This is in a Gui Btw. This is the Timer

Script #3. This makes the van move.

Script #4 Also in a GUi This is the scrip that makes it fade to black and say “Thanks for playing”

Script #5 The teleport

You’re firing all clients right?

When your local script calls to the server script to teleport a player, just plug that players variable into the function

image

I mean where it says :Connect(function() you put :Connect(function(Player)

That way you can delete the for loop. I think this is what is causing the TeleportService to get bottled. ALL clients in the game are firing that 1 time, which will double the amount of players to actually have. Just get the gameid, then fire that individual player. Since all clients fire the server, they will all be teleported individually without the need of a for loop. Haven’t tested this, but hopefully you get what I mean.

1 Like