Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i teleport a table of players?

i have this script that creates a timer when one or more players enter the lobby, once the timer is finished it will teleport the players to a game, but i want it to teleport all the players to the same server, and it seems like it teleports each player to a separate server instead.

while wait() do	
	if numofplayers.Value > 0 then
		repeat
			if numofplayers.Value > 0 then
				wait(1)
				timer.Value = timer.Value-1
			end
		until timer.Value == 0
		wait(2)
		print("Teleporting players")
		if #playerstotp > 0 then
			for i,v in pairs(playerstotp) do
				tpservice:Teleport(placeid, v)
				table.remove(playerstotp, i)
				print(#playerstotp)
			end
		end
		wait(3)
		numofplayers.Value = 0
	end
	
	players.PlayerRemoving:Connect(function(plr) 
		for i = 1, #playerstotp do
			if playerstotp[i] == plr then
				numofplayers.Value = numofplayers.Value-1
				table.remove(playerstotp, i)
				print(#playerstotp)
				print("looks like a player left!")
			end
		end	
	end)
end

2 answers

✓ Accepted answer

You can use the TeleportAsync function instead, which is like the Teleport function but with the support for multiple players, with the player(s) argument being a table, instead of an object.

It's also a yielding function which means that it pauses the thread until it finishes executing (IE: teleporting all players), this seems quite useful in your case as you want to wait for all players to teleport.

1 comment

1

Ok i worked i just had to change teleportasync to teleportpartyasync

So should it look something like this?

tpservice:TeleportAsync(placeid, playerstotp)

This discussion is preserved as it was. New answers, comments, and votes are closed.