My for loop isn't inserting players in to a table. I tried using tables but it doesn't work. Here's the part where the problem is:
local players = {} wait(5) for _, a in pairs(game.ReplicatedStorage.Players:GetChildren()) do table.insert(players, game.Players[a.Name]) end local code = game:GetService("TeleportService"):ReserveServer(9800587169) game:GetService("TeleportService"):TeleportToPrivateServer(9800587169, code, players)
✓ ANSWER ACCEPTED
For loop not inserting players into table?
1 answer
✓ Accepted answer
Hello,
You do not need a table what you can do is loop through Players directly. This will be obtained like:
local Players = game.Players -- Reference to your players
local code = game:GetService("TeleportService"):ReserveServer(9800587169) -- Private server
function TpAll()
for _, Player in pairs(Players:GetPlayers) do -- Loop through players
TS:TeleportToPrivateServer(9800587169,code,Player) -- Tp Player
end
end
TpAll()
wait(5)
if #Players > 0 then -- Recheck in case of failed Tp
TpAll()
end
More on TeleportService
More on Loops
More on Tables
I Hope this Helps
This discussion is preserved as it was. New answers, comments, and votes are closed.

7 comments
I'll check out later because ReserveServer is not on studio and i can't play test rn!
Ok! Glad you replied! if it doesn't work the problem will be in line 7.
I think it worked
Just need to change some things around
btw in recheck its if #Players:GetChildren i might of made a mistake
ok i fixed it
I suppose it is fixed.