How to make a system that when there is 1 player or less, players get teleported

Hello, I want to make a system that when there is 1 or less player touching the part, players get teleported to the lobby. I am using a script from TheDevKing’s tutorial on how to make an intermission (Also the DevForum community helped me with the randomizing map system). I think I have to use 1 or <1, but I don’t know how to script that, and put it in the intermission script. I would like some examples, or tutorials. Thank you.

Here is the script:

local spawnsFolder = game.Workspace.Spawns
local spawnAreas = game.Workspace.Spawns:GetChildren()
local roundLength = 100
local intermissionTimer = 25

local inRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status

local Lobby = game.Workspace.LobbyTeleport
local GameAreaTeleport = spawnAreas[math.random(1, #spawnAreas)]


inRound.Changed:Connect(function()
	wait(1)
	GameAreaTeleport = spawnAreas[math.random(1, #spawnAreas)]
	if inRound.Value == true then
		for _, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			char:MoveTo(GameAreaTeleport.Position)		
		end
		
	else
		
		for _, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			char.HumanoidRootPart.CFrame = Lobby.CFrame
		end
	end
end)


local function roundTimer()
	while wait() do
		for i = intermissionTimer, 1, -1 do
			inRound.Value = false
			wait(1)
			Status.Value = "Intermission: ".. i .." seconds left!"
		end
		for i = roundLength, 1, -1 do
			inRound.Value = true
			wait(1)
			Status.Value = "Game: ".. i .." seconds left!"
		end
			
		end
	end

spawn(roundTimer)
1 Like

What part is it? Is it in the script, if so could ya show me where

1 Like

I didn’t say it was in the script, I don’t know how to script that, so I want some tutorials, or examples.

To Check How Many Players Are In Game,
You Can Use

if #game.Players:GetPlayers < 1 then -- Players In Game are 0 (Server Is Empty)
    -- What you Want to Do
end
1 Like

Thanks, but is there a way that you can check how many player are touching the part?

Do I do

if game.Workspace.AreaPart.Players:GetPlayers < 1 then

end

(like you metioned)

?

Make a table. Insert the player that is touching the part inside the table. Remove the player that isn’t touching by doing Part:GetTouchingParts()

1 Like

So, for examples, do I do like this?

local areaPart = game.Workspace.AreaPart
local part = {areaPart}
if #part < 1 then 
   print("No One is Touching the Part!")
end

Well,
You should Possibly Use Region3 to Check if Player Is Around the Part.

If the Player is Around the Part,
Then add the Player to a Table and If He Is Gone, Remove The Player From the Table.

Now You Know who is Near the Part / Touching the Part.
Now you can Simply Check if Players Touching the Part / Near the Part Is Greater than 1 or not.

You can Learn About Region3 Using This Tutorial :

Instead of Playing A Sound, You Simply Need A Remote Event.
Just Fire the Remote Event to the Server when A Player Enters the Region.

The Server Will Add the Player to the Table.

local PlayersInPartRegion = {} -- Table

game.ReplicatedStorage.AddPlayerToTable.OnServerEvent:Connect(function(PlayerToAdd)
	table.insert(PlayersInPartRegion,PlayerToAdd.Name)
end)

game.ReplicatedStorage.RemovePlayerFromTable.OnServerEvent:Connect(function(PlayerToRem)
	local Count = 0
	for _,index in pairs(PlayersInPartRegion) do
		Count = Count + 1 
		if index == PlayerToRem.Name then -- Found Player Name
			table.remove(PlayersInPartRegion,Count)
			break
		end
	end
end)

-- Now You Need to Check if The Players Near the Part / Touching the Part are More than 1.

if #PlayersInPartRegion > 1 then -- Atleast 1 Player Near
	-- Do what You want to
end
1 Like

Thank you! Can I use this script for my game?

1 Like

Well i Guess You can
But This is not the Complete Script.

You need to Script the Region3 Which Fires these Events.

1 Like