Teleport to private server doesn't work reliably?

I have a story game, and I use teleport party to private server. It works with small groups, but with groups of 8, it doesn’t teleport them all. Is there a way to fix this?
My code:

local code = TS:ReserveServer(placeId) 
local players = group1
for i,v in pairs(group1) do
	table.remove(group1, i)
end
local success, result = pcall(function()
return TS:TeleportToPrivateServer(placeId,code,players)
end)

I think you have a slight misinterpretation of how tables work in lua. Think of a table like an object. When you set a new variable to an already existing table, it isn’t making a copy, it is literally pointing to the same table. You seem to be trying to make a copy of group1, and then clear the players from group1, and then teleport the players that were in it. Try code like this:

local players = group1
group1 = {}

This code will make the players variable point to the group1 table, then set the group1 variable to point to a new and empty table.

3 Likes

This worked! Thank you so much. It saved my game!

1 Like
players = {1,2,3,4,5,6,7,8}

for i, v in pairs(players) do
	print(v) 
	table.remove(players, i)
end

this prints 1,3,5,7

why?
table.remove shifts contents after removal
so after removing 1 from index 1
2 is at index 1 and your next index 2 has a 3

you were leaving half of your people inside the group

1 Like

Ohhh I see. Both these solutions work perfectly.

Pharyx_Styx is explaining another unintended piece of code that is causing it to only teleport half of the players. This part isn’t important because you should replace the code, but it explains why half of the players were teleporting.

Wait this works, but sometimes it doesn’t teleport 1 or 2 players. Sometimes more.

Could I see your current code?

joinable1 = false
	for i,v in pairs(group1) do
		game.ReplicatedStorage.ElevatorUI:FireClient(v, "open")
	end
	de1 = false
	count1 = 0
local code = TS:ReserveServer(placeId) 
local players = group1
local success, result = pcall(function()
return TS:TeleportToPrivateServer(placeId,code,players)
end)
group1 = {}
countdown1 = false
de1 = true
wait(10)
joinable1 = true

This code looks good to me. I’d suggest adding the snippet below, right before teleporting, to check if it is working as expected. The game should print in output all of the players that are intended to be teleported.

print('teleporting group 1')
for i,v in pairs(players) do
print(v)
end

The problem was the server count was only 10, not 15.

For future reference, the proper terminology for this behaviour is passing by reference. Just in case you ever want to look that up.

cc @CaptainD_veloper

1 Like