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

I can make a place teleporter, but I need it to teleport more people at a time. How can I fix this?

Asked by 6 years ago
Edited 6 years ago

I know I can teleport 1 player at a time with this block of code:

local TeleportService=game:GetService("TeleportService")
local Place=1651711943

script.Parent.Touched:connect(function(hit)
    local player=game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        TeleportService:Teleport(Place, player)
    end
end)

But how do I do it with multiple people at a time and that needs that number of people?

0
Use region3 and get how many players are in that area and once it reaches your limit or whatever then teleport. UltraUnitMode 419 — 6y

2 answers

Log in to vote
0
Answered by
l_337 15
6 years ago
local TeleportService=game:GetService("TeleportService")
local Place=1651711943

script.Parent.Touched:connect(function(hit)
for i, player in ipairs(game.Players:GetChildren()) do
TeleportService:Teleport(Place, player)
end
end)

thats to tp everyone at once now the other part i think u meant how to teleport a certain number of people ?


local TeleportService=game:GetService("TeleportService") local Place=1651711943 local numtp=3 script.Parent.Touched:connect(function(hit) while numtp >0 do for i, player in ipairs(game.Players:GetChildren()) do TeleportService:Teleport(Place, player) numtp = numtp-1 end end end)
0
Thank you! Skepticalitys 31 — 6y
0
I don't think you nested those loops correctly justoboy13 153 — 6y
0
Ok, sorry about that. Skepticalitys 31 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

I think this is what l_337 was trying to do

local TeleportService=game:GetService("TeleportService")
local Place=1651711943
local numtp=3


script.Parent.Touched:connect(function(hit)
    for i, player in ipairs(game.Players:GetChildren()) do
        if numtp > 0 then
            TeleportService:Teleport(Place, player)
            numtp = numtp-1
        end
    end
    numtp=3--resets numtp so that you can tp 3 more people next time it is touched
end)
0
Yeah you are right, I got a bit confused there l_337 15 — 6y
0
Happens to the best of us. justoboy13 153 — 6y

Answer this question