Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to follow a player to a server? (Teleport Service)

Asked by 6 years ago
Edited 6 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.

local TeleportService = game:GetService("TeleportService")
local levelId = 1370155526

function onTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then      
        local inParty = player.inParty.value
        local isHost = player.isHosting.value       
        if(inParty)then
            if(not isHost)then
                print("Only the party leader can join a game.")
                return
            end
        end
        player.Character.Humanoid.WalkSpeed = 0
        game.Workspace.Map.Soundz.Bell:Play()
        TeleportService:Teleport(levelId, player)
    end     
end




game.Players.PlayerRemoving:connect(function(player)
    wait(5)
    print("oi")
    for _, player2 in pairs(game.Players:GetPlayers()) do
        if(player2.followPlayer.Value == player.Name)then
            followPlayer(player2, player.UserId)
        end
    end
end)

function followPlayer(player, targetUserId)
    local success, errorMsg, placeId, instanceId = TeleportService:GetPlayerPlaceInstanceAsync(targetUserId)
    if success then
        TeleportService:TeleportToPlaceInstance(placeId, instanceId, player)
    else
        print("Teleport error:", errorMsg)
    end
end

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.

Answer this question