Unable to cast string to int64 error using place teleporter but it only happens half the time

Hi! I made a game teleport board that shows info about a game and has a button to teleport to the game. it also includes the game icon that is found via the game id, it works %100 of the time.

One of the goals for the board is to have it so that all you need to do is, take it from the toolbox and put it into the workspace, and just add a game name, description, and the game ID into the board info script.

problem is, the teleport script gets the game id from the same place as the game icon using the same method. but, half the time the teleport script works and teleports the player after they click the button, and half the time it just gives me an “Unable to cast string to int64” error. I have seen posts saying I should use pcall, but I have no clue how to use it and can’t seem to find any info on it for what I currently need.

I have tried relatively hard to figure it out but still, I can’t seem to find an understandable solution to this. and I only have about 1 and a half years of experience in Scripting, so if you could, can you please explain how to use a pcall for this script?

here is the Model.

here is the teleport script

local TeleportService = game:GetService(“TeleportService”)
local GetID = script.Parent.Parent.Parent.BoardInfoStorage.GameID.Value
local TeleportID = “”
TeleportID = GetID

TeleportService:Teleport(TeleportID, game.Players:WaitForChild(player.Name))

1 Like

A pcall is useful for things that aren’t script errors.
Use tonumber() on TeleportID (it’s a string), or just make it initialize as nil then set a number value.

But how do I fix the error with it? I’ve tried for hours now and cant find a fix?

According to your error, you are trying to use a string as a numerical value.
tonumber() picks up any string which has number-like qualities in a string, and turns them into a real number value.

As for your question, run the TeleportID through tonumber().

1 Like