How to follow a player to a server? (Teleport Service)
Asked by
7 years ago Edited 7 years ago
I'm working on a little party system but got stuck a bit with the player following system. Now I could be wrong with the issue but, what I believe is causing the issue, is that when the player leaves the game try's to pull everyone that is in their party to their server but because they haven't loaded into the actual game yet they cannot follow them. (and so are teleported to the same server) How would I have the players in the party wait for the party host to be in the game server? Here is a full set of source code attached to a portal object.
01 | local TeleportService = game:GetService( "TeleportService" ) |
02 | local levelId = 1370155526 |
04 | function onTouched(hit) |
05 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
07 | local inParty = player.inParty.value |
08 | local isHost = player.isHosting.value |
11 | print ( "Only the party leader can join a game." ) |
15 | player.Character.Humanoid.WalkSpeed = 0 |
16 | game.Workspace.Map.Soundz.Bell:Play() |
17 | TeleportService:Teleport(levelId, player) |
24 | game.Players.PlayerRemoving:connect( function (player) |
27 | for _, player 2 in pairs (game.Players:GetPlayers()) do |
28 | if (player 2. followPlayer.Value = = player.Name) then |
29 | followPlayer(player 2 , player.UserId) |
34 | function followPlayer(player, targetUserId) |
35 | local success, errorMsg, placeId, instanceId = TeleportService:GetPlayerPlaceInstanceAsync(targetUserId) |
37 | TeleportService:TeleportToPlaceInstance(placeId, instanceId, player) |
39 | print ( "Teleport error:" , errorMsg) |
43 | script.Parent.Touched:connect(onTouched) |
the followPlayer , isHosting, and playerFollow values are created inside another script, these are just to keep track of what party you are in and are edited by an outside source. This is purely just for the teleportation script.