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

Unable to cast value to Object?

local TS = game:GetService("TeleportService")
local Players = game:GetService("Players")
local code = TS:ReserveServer(1144760042)
local players = Players[HostName.Value].userId -- StringValue
TS:TeleportToPrivateServer(1144760042,code,players)

Can anyone help with this? I can't get around this issue

Error: Unable to cast value to Objects < TS:TeleportToPrivateServer(1144760042,code,players)

2 comments

0

"players" holds the service not the the array of players, to get an array of players use game:GetService("Players"):GetPlayers()

0

But doesn't game:GetService("Players"):GetPlayers() Grab all Players? As I'm trying to just grab 1 player

1 answer

✓ Accepted answer

Edit:

void TeleportToPrivateServer (
    int placeId,
    string reservedServerAccessCode,
    array<Player> players,
    string spawnName = "",
    Variant teleportData,
    ScreenGui customLoadingScreen = nil
)

TeleportToPrivateServer calls for an array of Player, an Object, not an array of userIds. Pass an array of players to the function;

players = {};
table.insert(players, game.Players[Hostname.Value]);
TS:TeleportToPrivateServer(placeid, code, players);

3 comments

0

what the hell? GetChildren() returns a dictionary, not an array. so you can't index it with a string

0

array GetChildren (); GetChildren() returns an array, and you have arrays and dictionaries reversed. Misinterpreted the problem and working on an edit. http://wiki.roblox.com/index.php?title=Table#Arrays

0

Ah, Okay thanks.

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