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

For loop not inserting players into table?

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)

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

7 comments

0

I'll check out later because ReserveServer is not on studio and i can't play test rn!

0

Ok! Glad you replied! if it doesn't work the problem will be in line 7.

0

I think it worked

0

Just need to change some things around

0

btw in recheck its if #Players:GetChildren i might of made a mistake

0

ok i fixed it

0

I suppose it is fixed.

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