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

How To Make A Group Teleporting System?

Asked by
OFF_S4LE 127
3 years ago

I decided to change the idea, to making it so there is a circle where you enter it and it teleports you.

My seat script :

local seats = workspace.Seats.One

local teleportService = game:GetService("TeleportService")

local num = 0

local playersInSeats = {}

local countdown = false

-- remove the prints if you'd like

local function countDown()

    if not countdown then 

        countdown = true

        print("Start countdown")
        playersInSeats = {}

        for i = 5,1,-1 do 

            if num < 1 then break end -- if everyone gets off, reset timer
            if num == #seats:GetChildren() then break end -- if seats are full, teleport
            wait(1)

        end

        if num >= 1 then -- change this to minimum number of players

            print("Start game")

            local serverCode = teleportService:ReserveServer(game.PlaceId) -- change game.PlaceId to the place id

            for _,seat in pairs(seats:GetChildren()) do

                if seat.Occupant then

                    local plr = game.Players:GetPlayerFromCharacter(seat.Occupant.Parent) -- occupant is the humanoid, hence why

                    table.insert(playersInSeats,plr)

                end

            end

            for _,plr in pairs(playersInSeats) do -- can remove this if you like, it was to debug

                print(plr)

            end

            teleportService:TeleportToPrivateServer(game.PlaceId,serverCode,playersInSeats) -- change game.PlaceId to the place id

            countdown = false

        else

            countdown = false

        end

    end

end

for _,seat in pairs(seats:GetChildren()) do

    if seat:IsA("Seat") then

        seat:GetPropertyChangedSignal("Occupant"):connect(function()

            if seat.Occupant ~= nil then

                num = num + 1
                countDown()

            else

                num = num - 1

            end

        end)

    end

end

Answer this question