I need help, when I put the script I get an error:
and when I put the script in the console it goes perfectly
Script:
local TS = game:GetService("TeleportService")
local Players = game:GetService("Players")
local code = TS:ReserveServer(4810749712)
local players = Players:GetPlayers()
wait(4)
TS:TeleportToPrivateServer(4810749712,code,players)
The context of your script is vague. If this runs immediately when the server starts, it may see no players added and thus return an empty table, causing that error.
local TS = game:GetService("TeleportService")
local Players = game:GetService("Players")
local code = game:GetService("TeleportService"):ReserveServer(4810749712)
local players = Players:GetPlayers()
wait(4)
TS:TeleportToPrivateServer(4810749712,code,{players})
-- just make sure that there are players in the game before calling TeleportPlayers.
local TS = game:GetService("TeleportService")
local Players = game:GetService("Players")
local function TeleportPlayers()
local code = TS:ReserveServer(4810749712)
local players = Players:GetPlayers() do
TS:TeleportToPrivateServer(4810749712,code,players)
end
end
wait(10)
TeleportPlayers()
It gives an error indicating this, so something else is wrong with the code as it says the argument is nil. If it was not nil, it would say that it does not work in studio.
This error is strange because GetPlayers will (or should) return an array when it’s called regardless of if it’s blank or not. Please try debugging your code by adding print statements to verify that the items you’re working with are non-nil.