In short
int64 is a whole number. Functions that take IDs, such as TeleportAsync, PromptProductPurchase, GetNameFromUserIdAsync and UserOwnsGamePassAsync, need a number. If you pass text, even text that looks like a number such as "123", Roblox stops with this error. Convert it with tonumber() and check the result is not nil before you call the function.
What the message means
ServerScriptService.Teleporter:7: Unable to cast string to int64
Other forms of the same message:
Unable to cast Instance to int64
The text usually comes from a TextBox, a StringValue, an attribute set as a string, or a chat command. All of those give you a string.
The other variants mean the same thing for other types: Unable to cast Instance to int64 means you passed an object (often a Player instead of player.UserId).
Causes and fixes
Two things cause this error in practice. Each one below has the smallest code that triggers it, then the fix.
An ID read from text
A TextBox, a chat command or a StringValue holds the ID as text.
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local placeIdValue = workspace:WaitForChild("Portal"):WaitForChild("PlaceId") -- a StringValue
Players.PlayerAdded:Connect(function(player)
-- Unable to cast string to int64
TeleportService:TeleportAsync(placeIdValue.Value, { player })
end)
Convert with tonumber, check it worked, and only then call the function. Better still, store IDs in an IntValue or a number attribute.
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local placeIdValue = workspace:WaitForChild("Portal"):WaitForChild("PlaceId") :: StringValue
Players.PlayerAdded:Connect(function(player: Player)
local placeId = tonumber(placeIdValue.Value)
if not placeId then
warn("PlaceId is not a number:", placeIdValue.Value)
return
end
local ok, err = pcall(function()
return TeleportService:TeleportAsync(placeId, { player })
end)
if not ok then
warn("Teleport failed:", err)
end
end)
A Player instead of a UserId
Functions that ask for a user ID want player.UserId, not the Player object. That gives the variant Unable to cast Instance to int64.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local VIP_PASS = 123456
Players.PlayerAdded:Connect(function(player)
-- Unable to cast Instance to int64
local owns = MarketplaceService:UserOwnsGamePassAsync(player, VIP_PASS)
print(owns)
end)
Pass player.UserId, in a pcall because the call goes over the network.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local VIP_PASS = 123456
Players.PlayerAdded:Connect(function(player: Player)
local ok, owns = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, VIP_PASS)
end)
print(player.Name, ok and owns)
end)
Fix it in your place
Paste the error, RoCode fixes it in your place
Copy the line from Output and paste it here. RoCode opens the script it names in the place you have open in Studio, works out which of the causes above it is, and edits the code there instead of handing you a snippet to paste.
RoCode is an AI agent for Roblox Studio: it reads the scripts in the place you have open, finds the line and edits it there, and every change is an undo point. It runs on Windows or macOS with a desktop browser. Free to start, with free credits every day.
How to find the line that causes it
- Open Output (Window menu, or the Script tab), clear it with Ctrl+K (⌘K on Mac), and press Play.
- Find the first red line. It starts with the script's place in the Explorer and the line number, such as
ServerScriptService.Shop:12:. - Click the red line. Studio opens that script with the cursor on the failing line.
- Read the lines between
Stack BeginandStack Endunder it: they list the calls that led there, newest first, so you can see which function called the broken one. - Still not sure which value is wrong? Add
print(typeof(x), x)just above the line, or set a breakpoint on it and read the values in the Watch window.
Questions
What is int64 in Roblox?
A whole number that can be very large, used for IDs: places, users, assets, game passes and developer products. In Luau you pass an ordinary number.
Why does "123" not work when it looks like a number?
Because it is text. Roblox converts text to numbers in a few places, but not for these ID arguments. tonumber("123") gives the number 123.
What does tonumber return for bad text?
nil. That is why the fix checks the result before calling the function.
Can RoCode fix it?
Yes. Paste the Output line into RoCode. It finds where the ID comes from in your place and converts or replaces it.
Sources and further reading
- Roblox Creator Docs: tonumber
- Roblox Creator Docs: Player.UserId
- Roblox Creator Docs: TeleportService:TeleportAsync
How the code was checked: every block marked Fixed passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 12 November 2026), and every block marked Breaks compiles and fails only when it runs. The message format "Unable to cast %s to %s" was checked against the strings in Roblox Studio itself (macOS build installed on 12 November 2026) on 12 November 2026. A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.