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

how to teleport 2 players to a private server with a countdown (it must be touchable)?

Asked by 5 years ago
Edited 5 years ago

I need to teleport 2 players to a privete server with a countdown i don't have much idea about group teleportation can you guys help me about this and do you know a way to make the countdown with it.

1
Not a req site. kittonlover101 201 — 5y
0
Yup, not a request site! BashGuy10 384 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Assuming you are asking for a full tutorial on how to teleport multiple players to another place in the same game, I am here to give you the full tutorial.

Theoretically, you could teleport multiple players with things other than a part, but for simplicity, this will be using a part to teleport multiple players.

What you want to do is create a Part in Workspace. You can do whatever you want to this part, as long as multiple players are able to touch this part. After you have placed the part in Workspace, place a Script inside the part.

Inside the script, the code should look something like this:

local Players = game.Players
local PlayersTouching = {}
local Timer = 10
local NeededPlayers = 1 -- Change to amount of players needed to start timer
local PlaceId = 0 -- Place GameId here

local Toucher = script.Parent
local RunService = game:GetService("RunService")
local TeleportService = game:GetService("TeleportService")

function IsPlayer(obj)
    if obj.Parent:IsA("Model") and obj.Parent:findFirstChild("Humanoid") then
        if Players:GetPlayerFromCharacter(obj.Parent) ~= nil then
            return true
        end
    end

    return false
end

function TeleportPlayers()
    local PrivateServerId = TeleportService:ReserveServer(PlaceId)
    TeleportService:TeleportToPrivateServer(PlaceId, PrivateServerId, PlayersTouching)
end

Toucher.Touched:connect(function(obj)
    if IsPlayer(obj) then
        local CurChar = obj.Parent
        local CurPlayer = Players:GetPlayerFromCharacter(CurChar)
        local index

        for i,v in pairs(PlayersTouching) do
            if v == CurPlayer then
                index = i
            end
        end

        if not index then
            table.insert(PlayersTouching, CurPlayer)
        end
    end
end)


Toucher.TouchEnded:connect(function(obj)
    if IsPlayer(obj) then
        local CurChar = obj.Parent
        local CurPlayer = Players:GetPlayerFromCharacter(CurChar)
        local index

        for i,v in pairs(PlayersTouching) do
            if v == CurPlayer then
                index = i
            end
        end

        if index then
            table.remove(PlayersTouching, index)
        end
    end
end)


local TimerRunning = false
local CurTime = Timer
local LastTick = tick()
RunService.Stepped:connect(function()
    if #PlayersTouching >= NeededPlayers then
        TimerRunning = true
    else
        TimerRunning = false
        CurTime = Timer
    end

    if TimerRunning then
        CurTime = CurTime-(tick()-LastTick)
        if CurTime <= 0 then
            TeleportPlayers()
            TimerRunning = false
            CurTime = Timer
        end
    end

    print(CurTime)
    for i,v in pairs(PlayersTouching) do print(v.Name) end
    LastTick = tick()
end)

Extra advice: In order to make sure that the Toucher.TouchEnded event does not fire when it is not needed to fire, it is important to make sure that the Part that was placed in Workspace is not collidable, anchored, transparent, and touches all parts of the Character. This can be done by creating a very large part that covers a lot of area.

I hope that helps! :D

0
You are an awesome human this looks perfect i will try. thank you TheMostDelikanliMan -14 — 5y
Ad
Log in to vote
1
Answered by
RSASDSA 72
5 years ago
Edited 5 years ago

To teleport any number of players to a private server, you have to use the TeleportService, specifically TeleportService:ReserveServer and TeleportService:TeleportToPrivateServer (linking to rbxts types docs for that function because the devhub is terrible) First, you have to create a private server with TeleportService:ReserveServer.

local TeleportService = game:GetService("TeleportService")
local serverAccessCode = TeleportService:ReserveServer(game.PlaceId)

Then, you have to get the group of players.

local playersYouWantToTeleport = {} -- This should be an array of Players

To make the delay we use the wait function

local delayTime = 30
wait(delayTime)

And to teleport the players we use TeleportService:TeleportToPrivateServer

TeleportService:TeleportToPrivateServer(game.PlaceId, serverAccessCode, playersYouWantToTeleport)

Answer this question