Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Unable to cast value to Object?

Asked by
Kuzx 22
7 years ago
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)

0
"players" holds the service not the the array of players, to get an array of players use game:GetService("Players"):GetPlayers() User#5423 17 — 7y
0
But doesn't game:GetService("Players"):GetPlayers() Grab all Players? As I'm trying to just grab 1 player Kuzx 22 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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);
0
what the hell? GetChildren() returns a dictionary, not an array. so you can't index it with a string creeperhunter76 554 — 7y
0
array<Instance> 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 KidTech101 376 — 7y
0
Ah, Okay thanks. Kuzx 22 — 7y
Ad

Answer this question