Help with this script

I want it so every player that is standing in a tunnel when the timer goes, is teleported to a server of the game. I know how to do the teleporting bit, but not for a group of players.
robloxapp-20210731-0902339.wmv (2.9 MB) Please help. I can’t figure this out. How would I teleport only the players that are standing in the area?

1 Like

Sorry that the video is a download. :frowning_face:

First, you need to set up a Region3.
Region3 | Roblox Creator Documentation.

Next, loop through all the parts.

local PlrsToTp = {}

for _, Part in pairs(workspace:FindPartsInRegion3(YourRegion)) do
  if Part.Parent:FindFirstChild("Humanoid") then
      if game.Players:GetPlayerByCharacter(Part.Parent) then
        table.insert(PlrsToTp, game.Players:GetPlayerByCharacter(Part.Parent))
     end
  end
end

Finally, use this:
https://developer.roblox.com/en-us/api-reference/function/TeleportService/TeleportPartyAsync

I made it work without a region 3 using this:

local timer = game.StarterGui.timer
local inpart = workspace.inpart
local plr = game.Players.LocalPlayer
local text = plr.PlayerGui:WaitForChild("ScreenGui").intext
local plrs = game.Players
local text1 = text.intext1
text.Visible = false

local Players = game:GetService("Players")

local function PopupReady(hit)
	local player = Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		text.Visible = true
	end
end

local function PopupGone(hit)
	local player = Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		text.Visible = false
	end
end

inpart.Touched:Connect(PopupReady)

inpart.TouchEnded:Connect(PopupGone)

so I don’t think I’ll be needing that…

If I did need that, what do you mean by,

?

Oh, it’ll still work without Region3. Just use the TeleportPartyAsync.

Also, you must do this in a server script.

so, did you watch the video. That script I just showed you, is what makes the “You’re in!” text pop up. do I copy that into ServerScriptService? obviously, if I did, I would tweak it so that it wasn’t controlling the popup, lol.

Can you please walk me through what I should do. I am confused.

Ok, so do the Region3/Teleport steps above. You put the FindParts in a loop. Then loop through all the players and make the popup visible

How can I do it without using region 3?

Without using that it would be less reliable, but you can use .Touched with a part in the zone you would like. Then just insert the player in a table and teleport all players in that table.

Is there a way to find all the players up to, say 5 (The maximum players that can come at a time is 5 in my game) and then put them in a list, if timer =< 0 then
--(Teleport all players who are touching the part.)
--This is the bit that I need help with.

1 Like