Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

For loop not inserting players into table?

Asked by 2 years ago

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

Log in to vote
0
Answered by 2 years ago

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

0
I'll check out later because ReserveServer is not on studio and i can't play test rn! User#47934 5 — 2y
0
Ok! Glad you replied! if it doesn't work the problem will be in line 7. Hi_People1133 218 — 2y
0
I think it worked User#47934 5 — 2y
0
Just need to change some things around User#47934 5 — 2y
View all comments (3 more)
0
btw in recheck its if #Players:GetChildren i might of made a mistake Hi_People1133 218 — 2y
0
ok i fixed it User#47934 5 — 2y
0
I suppose it is fixed. User#47934 5 — 2y
Ad

Answer this question