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)
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