Unable to cast value to Object

so im making a elevator for my tower defense game, but when i try teleporting, it errors:

Unable to cast value to Object

the code that teleports the players in the elevator is:

function players.teleport()
	local code = teleportservice:ReserveServer(7393530683)
	teleportservice:TeleportToPrivateServer(7393530683,code,players)
end

players is a table that contatins the ids of the players who have entered the elevator

1 Like

Usually when I get this error it is because I wrote something wrong in one of the arguments. Maybe double check those.

i double checked it on the dev hub, i put all the arguments in order

Object is supposedly a table, so players is a table of more? Can we see that?

this is what is inside the table

  12:09:55.784   ▼  {
                    [1] = 817297832,
                    ["teleport"] = "function"
                 }  -  Server - Main:14

The Players table should contain the Player objects you want to teleport.

so the players names, not their ids?

No, the Player objects. The class. The instance.

I think I see what the problem is. Try looping trough the table in a for i,v in pairs loop. and then Teleport them one by one.

so just the player instance?

30

Yes. That is right.

local player = game.Players.PLAYERNAME

If all players are needed to teleport, do

local Players = game:GetService("Players"):GetPlayers()

Or some wanted players, do

table.insert(Players,player)