Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

"Unable To Cast Value To Object" With :TeleportToPrivateServer() ???

Basically i'm making a system that will teleport all the players in a lobby to a private server though i'm getting this error with a Normal Script in ServerScriptStorage. Here is the part of my script that will teleport the players in the lobby:

			PlayerList = game.Players:GetChildren()
			PlayersToSend = Lobby.Players:GetChildren()
			local TeleportService = game:GetService("TeleportService")
			local code = TeleportService:ReserveServer(5229734511)
			for i, v in pairs(PlayerList) do
				for j, w in pairs(PlayersToSend) do
					if PlayersToSend[j].Name == PlayerList[i].Name then
						TeleportService:TeleportToPrivateServer(5229734511,code,PlayerList[i])
					end
				end
			end

I'm getting the error of "Unable To Cast Value To Object" Please help.

1 answer

So when you send players using the teleport service, it requires that you give it a table of players. Even if you only want to send a single person, you need to wrap that player in a table. Thankfully here, it seems that won't be the case.

So with what I said before, your third argument in the TeleportToPrivateServer needs to be a table:

PlayerList = game.Players:GetChildren()
PlayersToSend = Lobby.Players:GetChildren()
local TeleportService = game:GetService("TeleportService")
local code = TeleportService:ReserveServer(5229734511)
for i, v in pairs(PlayerList) do
    for j, w in pairs(PlayersToSend) do
        if not PlayersToSend[j].Name == PlayerList[i].Name then
            PlayerList:Remove(i) --it removes the player from the player list if they aren't supposed to be sent.
        end
    end
end
TeleportService:TeleportToPrivateServer(5229734511,code,PlayerList)

3 comments

0

The Lobby.Players are IntValues

0

What do the int values represent?

0

I edited it so it would work with your previous system, just a little bit easier.

This discussion is preserved as it was. New answers, comments, and votes are closed.