Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

1 comment

0

Use region3 and get how many players are in that area and once it reaches your limit or whatever then teleport.

2 answers

✓ Accepted answer
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)

3 comments

0

Thank you!

0

I don't think you nested those loops correctly

0

Ok, sorry about that.

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)

2 comments

0

Yeah you are right, I got a bit confused there

0

Happens to the best of us.

This discussion is preserved as it was. New answers, comments, and votes are closed.