Roblox Studio error

Unable to cast string to int64

What Unable to cast string to int64 means in Roblox Studio, the two things that cause it with the code that triggers each, and the fix for each one.

Updated 12 November 20263 min readErrorLuauWritten by

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.

On this page
  1. What it means
  2. Causes and fixes
  3. Fix it with RoCode
  4. Find the line
  5. Questions
  6. Sources

What the message means

Output (example)
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.

Breaks Script in ServerScriptService named Teleporter
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.

Fixed Script in ServerScriptService named Teleporter
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.

Breaks Script in ServerScriptService named VipCheck
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.

Fixed Script in ServerScriptService named VipCheck
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.

For example: ServerScriptService.Teleporter:7: Unable to cast string to int64

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

  1. Open Output (Window menu, or the Script tab), clear it with Ctrl+K (⌘K on Mac), and press Play.
  2. Find the first red line. It starts with the script's place in the Explorer and the line number, such as ServerScriptService.Shop:12:.
  3. Click the red line. Studio opens that script with the cursor on the failing line.
  4. Read the lines between Stack Begin and Stack End under it: they list the calls that led there, newest first, so you can see which function called the broken one.
  5. 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

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.

More Roblox errors

All Roblox Studio errors

Stop hunting errors line by line.

RoCode reads the scripts in your open place, fixes the error where it happens and tells you what it changed. Free every day, no card required.