TeleportToPrivateServer not working

Hey everyone,
I’m teleporting players for my story game, and my script isn’t working.
Here is my script:

coroutine.wrap(function()
	while true do
		wait()
		for i = StartTime, 0, -1 do
			if i == 0 and game.ReplicatedStorage.PlayersInBus.Value >= MinPlayers then
				Teleporting = true
				for _, Player in pairs(BusTable) do
					game.ServerStorage.TeleportGui:Clone().Parent = Player.PlayerGui
					Player.Character:Destroy()
					Player.PlayerGui.ExitGui:Destroy()
				end
				local Code = TeleportService:ReserveServer(5191490565)
				for _, Player in pairs(BusTable) do
					local Remover = table.find(BusTable, Player)
					table.remove(BusTable, Remover)
					game.ReplicatedStorage.PlayersInBus.Value = #BusTable
				end
				
				TeleportService:TeleportToPrivateServer(5191490565, Code, BusTable)
				Teleporting = false
			elseif i == 0 and game.ReplicatedStorage.PlayersInBus.Value < MinPlayers then
				game.ReplicatedStorage.Status.Value = MinPlayers.. ' players needed!'
				wait(1)
			elseif game.ReplicatedStorage.PlayersInBus.Value == 12 then
				Teleporting = true
				for _, Player in pairs(BusTable) do
					game.ServerStorage.TeleportGui:Clone().Parent = Player.PlayerGui
					Player.Character:Destroy()
					Player.PlayerGui.ExitGui:Destroy()
				end
				local Code = TeleportService:ReserveServer(5191490565)
				for _, Player in pairs(BusTable) do
					local Remover = table.find(BusTable, Player)
					table.remove(BusTable, Remover)
					game.ReplicatedStorage.PlayersInBus.Value = #BusTable
				end
				
				TeleportService:TeleportToPrivateServer(5191490565, Code, BusTable)
				Teleporting = false
			end
			game.ReplicatedStorage.Status.Value = 'The bus is leaving in '..i..' seconds'
			wait(1)

		end
	end
end)()

The error I get is this:

Thanks for any help!

I’ve used this feature before and I don’t understand why it’s happening.

watch the Parameters of players

Uhm, Isn’t that what I’m going??

where the player ?
30 characterrrrrr

The bustable is a table…

On this script: Teleport Script not Working!

It actually worked, I don’t see a diference.

Nevermind, realised it was because I removed everyone before teleporting them.

1 Like

sorry i’m not sure i understand but i can give you an example

    local TS = game:GetService("TeleportService")
    local Players = game:GetService("Players")
    local DSS = game:GetService("DataStoreService")
    local DS = DSS:GetGlobalDataStore()

    -- Get the saved code
    local code = DS:GetAsync("ReservedServer")
    if type(code) ~= "string" then -- None saved, create one
    	code = TS:ReserveServer(game.PlaceId)
    	DS:SetAsync("ReservedServer",code) -- Save ServerCode with DataStore
    end	
TS:TeleportToPrivateServer(game.PlaceId,code,game.Players.USERNAME)	-- Teleport the user