Unable to cast value to Objects - Teleport Service

I currently have a script that teleports a number through the teleport service with the player, but currently it is saying giving me this error:

Unable to cast value to Objects

and it errors when I call for a teleport.

Here is my code:

	local TeleportService = game:GetService("TeleportService")
	print("ok")
	game.ReplicatedStorage.Teleport.OnServerEvent:Connect(function(player,teleportData) -- TeleportData is a number, I have it currently set at 1.
		print("okgotit") -- Just to make sure its working
	--local reservId = TeleportService:ReserveServer(-) ignore this, old stuff
		print("sending") -- Just to make sure its working
	TeleportService:TeleportPartyAsync(-removedplaceid-,player,teleportData,script.Load) --Removed the place id, it is correct though.
	end)

I am asking for your help, as whatever I have tried is not working.
Any help is appreciated. Thanks! :smile:

If your reply is unrelated to the error I am receiving, I kindly ask you could just message me about it or any other means of informing me, as I am only looking for the solution to this error and don’t want to crowd the replies. Thanks!

2 Likes

TeleportPartyAsync requires an array of players. A single player will not work. However, if you want to teleport a single player, you can create an array with just the player inside of it.

TeleportService:TeleportPartyAsync(-removedplaceid-,{player},teleportData,script.Load)

The whole point of TeleportPartyAsync is to ensure multiple players get into the same server, though. If you’re only teleporting a single player, I’d recommend looking into a different method such as Teleport (that method might even be better considering it does take a single player).

TeleportService:Teleport(-removedplaceid-,player,teleportData,script.Load)
6 Likes

Oh my gosh! I totally forgot that I was using that. I originally had an array of players, but I changed it to just the player. Thank you for telling me about my mistake.

Edit: This turned out to be the issue. I can’t believe I forgot to change that. Thanks for informing me.

1 Like

Yeah of course, that’s why we’re here! :slight_smile:

Advice: Normally an “unable to cast” error means that there is an incorrect type that cannot be converted, in this case player to array.

1 Like