"Unable to cast value to Objects" on TeleportToPrivateServer

Hello!

I’ve been recently trying to use the “ReserveServer” functions of the TeleportService.

However, when I’m trying to teleport, it says that.image

My code:

function onCalled(player, place)
	print(player, " - ", place) -- Don't mind that.
	local tpS = game:GetService("TeleportService")
	local code = tpS:ReserveServer(place)
	print(code) -- Don't mind that either.
	tpS:TeleportToPrivateServer(place, code, player) -- Line that errors.
end

game.ReplicatedStorage.TeleportPlayer.OnServerEvent:Connect(onCalled)

How to fix that?

Thanks in advance,
Mehdi

the player argument, has to be a table.

e.g. tpS:TeleportToPrivateServer(place, code, {player1, player2, ...})

2 Likes

Maybe your using a global var. Add .value to the end to get its value. Not sure were. But that’s what I recognize the error being. Maybe place is the object?

You’ll still get the object values name when printing place. But to pass its value, you’ll need to specify.

After double-checking the Developer Hub, it seems like you’re right.
Testing… It’s that! Thanks you alot.

Apparently had to use a player table.

2 Likes

I think you’re confusing global variables with Roblox’s Value objects. Global variables are just normal variables with a global scope, you don’t have to do anything special to get their values.

Also, player isn’t even a global variable. It’s a parameter to the onCalled function, so it’s localized to that function.

1 Like

Yeah, I didnt mean global variable in that sense.

I did mean value object. I’ve worked with many engines in the past, and that’s just how I refer to them I guess. Oops :slight_smile:

Sorry if it was misleading.

Just to clarify, a value object can be placed anywhere and shared among scripts. That’s global if you ask me.