I have a script which teleports a group of people to a sub-place. I need to wait for every player to join before I am able to start my game but I don’t know how I would go about doing this.
Any help with this is appreciated.
I have a script which teleports a group of people to a sub-place. I need to wait for every player to join before I am able to start my game but I don’t know how I would go about doing this.
Any help with this is appreciated.
You pass an array of players to TeleportService when you teleport players to a place, right?
Maybe you could pass this array with each player as the optional parameter TeleportOptions? Then, receive the teleportation info as each player joins the game, and take the length of the array using #. This will be the number of players teleporting to your game.
The only problem I can see with this would be if a player disconnects during the teleportation or if they leave the game. If that happens, then the actual number of players would be less than the initial array.
This is a good idea - on the topic of disconnecting, you could always just have a timer that ticks down until everyone has joined (or, of course, the timer reaches 0)
how do I receive the teleportation info?
Here is the link for some documentation I think you will find helpful for that:
https://create.roblox.com/docs/reference/engine/classes/TeleportService#GetLocalPlayerTeleportData
while trying to pass options (Im passing a number) I get the error “Unable to cast value to object”.
game:GetService("TeleportService"):TeleportAsync(gameId,{game.Players:FindFirstChild(v)},getLength(teleporting))
any ideas why?
TeleportOptions is not where you pass the custom data.
Here is the link for how to send custom user data when teleporting:
TeleportOptions acts like an Instance. In the code sample from the documentation, TeleportOptions is actually created using Instance.New("TeleportOptions")
To pass custom data, you must create a variable that is a new instance of TeleportOptions, and then use TeleportOptions:SetTeleportData() to actually set data.
If you are still confused, here is a small code sample that may help you:
local DataToTeleport = 5 --This can maybe be the total number of players you are teleporting
local TelOptions = Instance.New("TeleportOptions")
TelOptions:SetTeleportData(DataToTeleport)
TeleportService:TeleportAsync(PlaceID, {player}, TelOptions)
On the receiving end:
local teleportData = TeleportService:GetLocalPlayerTeleportData()
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.