TeleportService cannot cast string into int64

Hi! So my teleportation script keeps erroring saying it cannot cast string into int64, and I don’t understand what is wrong. Can anybody help me?

script.Parent.OnServerEvent:Connect(function(plr,sp)
	local success, errorMessage, placeId, jobId = pcall(function()
		return game:GetService("TeleportService"):GetPlayerPlaceInstanceAsync(sp)
	end)

	if success then
		-- Teleport player
		game:GetService("TeleportService"):TeleportToPlaceInstance(placeId, jobId, plr) --Error is located here.
	else
		warn(errorMessage)
	end
end)

Notes: sp is the players user id.

Additional Information can be given if needed.

1 Like

What line is this error originating from?

1 Like

Its coming from here:

game:GetService("TeleportService"):TeleportToPlaceInstance(placeId, jobId, plr) --Error is located here.

Can you add a print(type(sp), sp) add the very beginning of the remote event being fired?

Your pcall set errorMessage into a variable instead. Print out all the variables to see exactly why. There is no error message since all of its variables are returned in order starting from the second and so on.

An arbitrary test on pcall reveals:

local a, b, c = pcall(function()
    return "a", "cee", "LOL"
end)

print(a, b, c) -- true, "a", "cee"
1 Like

1 of them is completely blank for some reason.

I did that, 1 was completely blank.

Is sp intended to be the player that fired the remote or is it some sort of input?

That is because errorMessage is now the place ID and the placeId is now job ID when successful.

2 Likes

How do i prevent that from happening?

sp is the player’s userid to follow.

Since the pcall is using a return, remove errorMessage variable completely from it. If the pcall fails, just return the second argument as per usual.

1 Like

Assuming that value comes from a GUI input you should consider running it through tonumber(sp) on the server before sending the TeleportService teleport request.

This most likely isn’t the source of your error as Operatik explained.

How would I do this? (Sorry, im new to pcall.)

The pcall’s second return is a response. There is more information on this.


Alternarively, you want to set variables inside the pcall scope rather than using return. A lot like this example in the API reference:

3 Likes

Now it says: Cannot teleport to blank instance id, aborting.

Could you please send an update of the code and the error instead of the errors only?

1 Like

Edit: I fixed my code! Turns out i was forgetting 2 variables. Tysm for the help!

2 Likes