userni3
(user)
September 4, 2021, 8:59am
1
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
Very_TB
(Gulezzz)
September 4, 2021, 9:01am
2
Usually when I get this error it is because I wrote something wrong in one of the arguments. Maybe double check those.
userni3
(user)
September 4, 2021, 9:03am
3
i double checked it on the dev hub, i put all the arguments in order
octav20071
(OctaViano)
September 4, 2021, 9:09am
4
Object is supposedly a table, so players is a table of more? Can we see that?
userni3
(user)
September 4, 2021, 9:10am
5
this is what is inside the table
12:09:55.784 ▼ {
[1] = 817297832,
["teleport"] = "function"
} - Server - Main:14
octav20071
(OctaViano)
September 4, 2021, 9:13am
6
The Players table should contain the Player objects you want to teleport.
userni3
(user)
September 4, 2021, 9:13am
7
so the players names, not their ids?
octav20071
(OctaViano)
September 4, 2021, 9:14am
8
No, the Player objects. The class. The instance.
Very_TB
(Gulezzz)
September 4, 2021, 9:14am
9
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.
userni3
(user)
September 4, 2021, 9:15am
10
so just the player instance?
30
octav20071
(OctaViano)
September 4, 2021, 9:16am
11
Yes. That is right.
local player = game.Players.PLAYERNAME
octav20071
(OctaViano)
September 4, 2021, 9:18am
12
If all players are needed to teleport, do
local Players = game:GetService("Players"):GetPlayers()
Or some wanted players, do
table.insert(Players,player)