I have a multi-game place with the starter place as a hub where you can teleport to all the other places from. For a while, I've been using this to get from place to place with success:
game:GetService("TeleportService"):Teleport(placeID, player)
Then I found out that my friends in the U.K never get into the same servers as my other friends here in the United States, even though no server capacity limits have been reached. So I've decided to use the ReserveServer() function of the TeleportService to guarantee everyone gets into the same server.
I eventually coded this into my server script and testing it to see that I get the error "Unable to cast value to Object" on line 11 (eleven) when someone wants to teleport to the place called Holo. Here's the code (which is a normal script in ServerScriptService):
wait(1) local TeleportPlayer = game:GetService("ReplicatedStorage"):WaitForChild("TeleportPlayer")--event that's called when a player wants to teleport to a place local TeleportService = game:GetService("TeleportService")--teleport service local HoloReserveCode = TeleportService:ReserveServer(2164207568)--holo code local FortReserveCode = TeleportService:ReserveServer(2164380789)--fort code local BattleReserveCode = TeleportService:ReserveServer(2164277365)--battlegrounds code TeleportPlayer.OnServerEvent:connect(function(player, placeID) if placeID == 2164207568 then --holo TeleportService:TeleportToPrivateServer(placeID, HoloReserveCode, player) elseif placeID == 2164380789 then --fort TeleportService:TeleportToPrivateServer(placeID, FortReserveCode, player) elseif placeID == 2164277365 then--battlegrounds TeleportService:TeleportToPrivateServer(placeID, BattleReserveCode, player) end end)
I can use an explanation for why there's an error and a potential fix. Please comment below with more information you may need, and thanks for reading!
TeleportToPrivateServer
is an array, which consists of the Player
objects to teleport.wait(1) local TeleportPlayer = game:GetService("ReplicatedStorage"):WaitForChild("TeleportPlayer")--event that's called when a player wants to teleport to a place local TeleportService = game:GetService("TeleportService")--teleport service local HoloReserveCode = TeleportService:ReserveServer(2164207568)--holo code local FortReserveCode = TeleportService:ReserveServer(2164380789)--fort code local BattleReserveCode = TeleportService:ReserveServer(2164277365)--battlegrounds code TeleportPlayer.OnServerEvent:Connect(function(player, placeID) if placeID == 2164207568 then --holo TeleportService:TeleportToPrivateServer(placeID, HoloReserveCode, {player}) elseif placeID == 2164380789 then --fort TeleportService:TeleportToPrivateServer(placeID, FortReserveCode, {player}) elseif placeID == 2164277365 then--battlegrounds TeleportService:TeleportToPrivateServer(placeID, BattleReserveCode, {player}) end end)
player
in curly braces to make it an array.RBXScriptSignal:connect()
is deprecated and should not be used in new work, switch to RBXScriptSignal:Connect()
instead.