#After touching a part you get teleported to another place

1 messages · Page 1 of 1 (latest)

fervent sage
#

I have a game with multiple stages and need help with a part teleporting you after touching it. Any help that could get me closer to the solution would be appreciated

leaden latch
#

teleportservice

#

let me link the documentation rq

#

use this!

fervent sage
#

I have a lobby type game that will teleport you to the first stage that works perfectly but someone showed me to teleport it to a private server and it doesnt work

leaden latch
#

then teleport to a private server

#
teleportservice:reserveserver(placeid)
fervent sage
#

mhm

#

alright

#

ill check that later

leaden latch
#

i might have prewritten code somewhere

#

give me a second..

#

@fervent sage

fervent sage
#

oh

#

alr

#

imma just watch vids

leaden latch
#

wait no

#

im trying to send

#

the thing

#

but message limit lol

#

😭

fervent sage
#

dm me

#

i have my dms open

leaden latch
#

ill send it in two parts

fervent sage
#

you can just send it in dms

leaden latch
#
local TeleportService = game:GetService("TeleportService")

local PlayersToTeleport = {}
local ReplicatedStorage = game.ReplicatedStorage
local MinimumPlayers = 2
local MaximumPlayers = 32

function GetPlayersInQueue()
    local playersinqueue = 0
    for i,v in pairs(PlayersToTeleport) do
        if v == nil then continue end
        playersinqueue += 1
    end
    return playersinqueue
end

function TeleportAllPlayers()
    local players = {}
    local ReservedServer = TeleportService:ReserveServer(94129971080307)
    for i,v in pairs(PlayersToTeleport) do
        if game.Players:FindFirstChild(i) then
            table.insert(players, game.Players:FindFirstChild(i))
        end
    end
    TeleportService:TeleportToPrivateServer(94129971080307, ReservedServer, players)
    PlayersToTeleport = {}
end

script.Parent.Touched:Connect(function(hit)
    if GetPlayersInQueue() >= MaximumPlayers then return end
    if hit.Parent:FindFirstChildOfClass("Humanoid") then
        if game.Players:GetPlayerFromCharacter(hit.Parent) then
            if not PlayersToTeleport[game.Players:GetPlayerFromCharacter(hit.Parent).Name] then
                PlayersToTeleport[game.Players:GetPlayerFromCharacter(hit.Parent).Name] = true
                ReplicatedStorage.Events.ShowLeaveButton:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
            end
        end
    end
end)

ReplicatedStorage.Events.LeaveQueue.OnServerEvent:Connect(function(player)
    if PlayersToTeleport[player.Name] then
        PlayersToTeleport[player.Name] = nil
    end
end)
#

while task.wait() do

    repeat task.wait() 
        script.Parent.Players.TextLabel.Text = tostring(GetPlayersInQueue()).."/"..MaximumPlayers
        script.Parent.Timer.TextLabel.Text = "Waiting for "..MinimumPlayers.." players!"
    until GetPlayersInQueue() >= MinimumPlayers

    for i = 30,0,-1 do
        script.Parent.Players.TextLabel.Text = tostring(GetPlayersInQueue()).."/"..MaximumPlayers
        script.Parent.Timer.TextLabel.Text = "Teleporting in "..i.." seconds!"
        if GetPlayersInQueue() < MinimumPlayers then
            break
        end
        task.wait(1)
    end

    if GetPlayersInQueue() >= MinimumPlayers then
        TeleportAllPlayers()
    end
end

game.Players.PlayerRemoving:Connect(function(player)
    if PlayersToTeleport[player.Name] then
        PlayersToTeleport[player.Name] = nil
    end
end)
leaden latch
#

character limit i meant*

fervent sage
#

ohh

leaden latch
#

😔

fervent sage
#

right

#

but like a game teleporter

#

is there a way that there is one thats just like

#

simple?

#

kinda like a game teleporter but with a place id

leaden latch
#
function TeleportAllPlayers()
    local players = {}
    local ReservedServer = TeleportService:ReserveServer(94129971080307)
    for i,v in pairs(PlayersToTeleport) do
        if game.Players:FindFirstChild(i) then
            table.insert(players, game.Players:FindFirstChild(i))
        end
    end
    TeleportService:TeleportToPrivateServer(94129971080307, ReservedServer, players)
    PlayersToTeleport = {}
end

this is the main function

#

the rest is just

#

me proofing every single scenario ever

#
    local ReservedServer = TeleportService:ReserveServer(94129971080307)

see i reserve the server first

#
    for i,v in pairs(PlayersToTeleport) do
        if game.Players:FindFirstChild(i) then
            table.insert(players, game.Players:FindFirstChild(i))
        end
    end

gather players into a table

#
    TeleportService:TeleportToPrivateServer(94129971080307, ReservedServer, players)

then just teleport

fervent sage
#

mhm

#

alr

#

ill try it ot

#

out

#

so a script with this in the part?

#

but I need it to be after touching the part

leaden latch
#

also

#

teleports dont work in roblox studio

fervent sage
#

i know

leaden latch
#
    for i,v in pairs(PlayersToTeleport) do
        if game.Players:FindFirstChild(i) then
            table.insert(players, game.Players:FindFirstChild(i))
        end
    end

and gathering players is unnecessary if youre doing solo teleports

fervent sage
#

I wanna say I can send you the game

#

so you can try it out to see what im talking abou

#

t

leaden latch
# fervent sage t

im busy right now, perhaps later? for now you can attempt to create a teleport system with whatever bits of knowledge you have on teleport service

fervent sage
#

alr