So I was testing a feature in my game which was the loading screen to teleport to a game. But I ran into a problem. In the output, I saw an error called: Unable to cast value to Object.
This was the script I’ve been using.
local teleportservice = game:GetService("TeleportService")
local event = game.ReplicatedStorage.Teleport
local id = 1234567890 --i didnt add the game to the experience yet
event.OnServerEvent:Connect(function(player: Player)
teleportservice:TeleportAsync(id, {player.UserId})
end)
I tried teleporting the player model and the humanoid. But that also gave me errors. So if there is anyway to solve it, that would be great.
It turns out that the second argument of “TeleportAsync” should be a player instance instead of a user id. You can fix your issue by using this code:
local teleportservice = game:GetService("TeleportService")
local event = game.ReplicatedStorage.Teleport
local id = 1234567890
event.OnServerEvent:Connect(function(player: Player)
teleportservice:TeleportAsync(id, {player})
end)