Unable to cast string to int64 on a RemoteFunction?

The game I am currently working on uses multiple places, the main place is the title screen place. Basically, you hit play and you join the actual fighting game. The problem with this is that you can’t join any specific players game, including friends. To combat this, we put a “Join Username” GUI. You type someones name in the text box and hit join, and if they are in the game, then you will teleport to the server that they’re in.

Now the problem is, I keep getting this error that no coder I know understands. “unable to cast string on int64”. have no idea how it makes sense on the line it errored at. It is erroring at line 116.

--Join Username
joinFriend = container:WaitForChild("JoinFriend")
joinButton = joinFriend:WaitForChild("JoinButton")
usernameInput = joinFriend:WaitForChild("UsernameInput")
joinUsername = game:GetService("ReplicatedStorage"):WaitForChild("JoinUsername")

joinButton.MouseButton1Click:Connect(function()
    local name = usernameInput.Text --Target player's name.
	--print(name,joinUsername)
	local value = joinUsername:InvokeServer(name)
	if value == false then
   	spawn(function()
            usernameInput.Text = "User is not in-game."
            wait(3)
            if usernameInput.Text == "User is not in-game." then --Make sure they didn't edit while waiting
                usernameInput.Text = "Username"
            end
         end)
	end
end)

Line 116 is

local value = joinUsername:InvokeServer(name)

I don’t understand how a string is being cast on an integer.

Here is the server script where he RemoteFunction is set up.

game:GetService("ReplicatedStorage"):WaitForChild("JoinUsername").OnServerInvoke = function(player, name)
	local playerid = game:GetService("Players"):GetUserIdFromNameAsync(name)
	local wasFound, placeId, jobId
    local success, errorMessage = pcall(function()
    	wasFound, placeId, jobId = game:GetService("TeleportService"):GetPlayerPlaceInstanceAsync(playerid) --Return the players game instance if they are in-game.
    end)
	if success then
		game:GetService("TeleportService"):TeleportToPlaceInstance(placeId,jobId,player) 
		return true
	else
		print(errorMessage)
		return false				
	end
end

Thank you for the help.

That’s the error it gives when a function is supposed to accept a number, but you give it a string. It doesn’t make sense in the context of InvokeServer, though. Are you sure that script is the one that’s causing the error?

2 Likes

I know for a fact that this is the GUINavigation script. The only thing I can think of is that the error is occurring in the function on the server, but for some reason, its erroring with the Invoke being called instead of showing the error on the server, where the actual function is set up.

Actually, it’s likely the error is occurring server-side. Two errors get returned, one with a traceback on the server pointing to the line the error occurs on. But since the client invoked the server function it will also throw the same error because the function neither yields or returns a value; so any code flow on the client also gets interrupted.

Studio example

Screen Shot 2020-06-09 at 5.33.44 PM

This should at least you give some hint on where the problem is really occurring. I’m guessing the variable placeId isn’t what it’s supposed to be.
game:GetService("TeleportService"):TeleportToPlaceInstance(placeId,jobId,player)

Can’t confirm if this will work, because API function is a bit trickier to test than most.

But try
local success, errorMessage = pcall(function()
    placeId, jobId = game:GetService("TeleportService"):GetPlayerPlaceInstanceAsync(playerid)
end)
-- OR
local success, errorMessage, placeId, jobId = pcall(function()
    return game:GetService("TeleportService"):GetPlayerPlaceInstanceAsync(playerid)
end)

It appears Roblox mixed up the order of the tuple on the DevHub, which is the cause of the issue. Oops.

And because the error was displayed as clientside, it was harder than usual to debug.

Dev Hub order:

Actual order:

  1. currentInstance
  2. instanceId
  3. placeId

Python, I suggest you make a post about this on the DevHub feedback subforum.