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

Teleporting script only teleporting one player, instead of certain ones?

Asked by 4 years ago

My teleporting script is suppose to teleport everyone, but it's only teleporting the player who clicked. Not sure why its doing this, is there an error?

local remote = game.ReplicatedStorage.StartEvent
remote.OnServerEvent:Connect(function(player)
    for i, v in pairs(game.Players:GetPlayers()) do
        local bool = v:FindFirstChildOfClass("BoolValue")
        local frame = v.PlayerGui.ActiveLobbys.Frame.Frame.Frame
        local player2 = frame.PlayerName.Text
        local gameplaceid = 3313994275
        local Player = player
        local PlayersToTeleport = {}
        local AlreadyInTable = false

            for _,OtherPlayer in next,PlayersToTeleport do
                if OtherPlayer == Player then
                AlreadyInTable = true
            end
        end
        if not AlreadyInTable then
            table.insert(PlayersToTeleport,Player)
        end

            local TeleportService = game:GetService("TeleportService")
            local Reserve = TeleportService:ReserveServer(3313994275)

            TeleportService:TeleportToPrivateServer(gameplaceid, Reserve, PlayersToTeleport)
    end
end)

1 answer

Log in to vote
1
Answered by
Tokyo7979 131
4 years ago
Edited 4 years ago

Here this should help:

local TeleportService = game:GetService("TeleportService")
local Reserve = TeleportService:ReserveServer(3313994275)
for i,v in pairs(game.Players:GetChildren()) do
        table.insert(PlayerToTeleport,i,v.Name)
 end
for i,v in pairs(PlayersToTeleport) do
    TeleportService:TeleportToPrivateServer(gameplaceid, Reserve, PlayerToTeleport[v])
end

You should've called the TeleportService and the Reserve variables at the start of the script to avoid changing lines etc. What I did here is that I looked how much player's there where, and teleported each player 1 by 1 in a for i,v loop.

0
Unable to cast value to objects line 9? zandefear4 90 — 4y
0
Edited the showcase in my response. Hopefully this works..? Tokyo7979 131 — 4y
0
I already changed it to work, but Ill try this. zandefear4 90 — 4y
0
The v doesn't work in the teleporting part. zandefear4 90 — 4y
0
I just erased it. zandefear4 90 — 4y
Ad

Answer this question