I've been working a tower defense game in Roblox, and I have been trying to add a teleport system, but I get the error (unable to cast array to int64) in the output. The script is to reserve the server, and teleport the players to that private server.
Here's the code:
01 | local MapCollection = { 4895754098 } |
02 | local MapID = MapCollection |
03 |
04 | function onTouched(hit) |
05 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
06 | local access = game:GetService( "TeleportService" ):ReserveServer(MapID) |
07 | game:GetService( "TeleportService" ):TeleportToPrivateServer(MapID,access, { player } ) |
08 | end |
09 |
10 |
11 | script.Parent.Touched:connect(onTouched) |
I would like a reply so I can fix the script as soon as possible.
Thanks, notreallysupernova
The first parameter of TeleportService:TeleportToPrivateServer() and TeleportService:ReserveServer() is a number. You are giving a table.
01 | local MapCollection = 4895754098 |
02 | local MapID = MapCollection |
03 |
04 | function onTouched(hit) |
05 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
06 | local access = game:GetService( "TeleportService" ):ReserveServer(MapID) |
07 | game:GetService( "TeleportService" ):TeleportToPrivateServer(MapID,access, { player } ) |
08 | end |
09 |
10 |
11 | script.Parent.Touched:connect(onTouched) |
Your variable MapID
is incorrect. You are referencing the entire array (MapCollection) while in your usecase to get the place id, you need to reference a specific index inside the array.
Try this:
1 | local MapID = MapCollection [ 1 ] |
2 | print (MapID) |
3 |
4 | -- Output: |
5 | -- 4895754098 |