Hello, I want to make a system that when a player teleports, the timer sets again. My game is has intermission, and game time. When there are 1 or 0 players, the player gets teleported back to the lobby. When the player gets teleported back, the timer doesn’t reset to the intermission timer. I would like some examples, or tutorials. Thank you.
PlayerCheckingScript(Credits to @Alvin_Blox, and @YT_Forceman):
local lobby = game.Workspace.LobbyTeleport
local inRound = game.ReplicatedStorage.InRound
local playersInPartRegion = {}
game.ReplicatedStorage.AddPlayerToTable.OnServerEvent:Connect(function(playerToAdd)
if not table.find(playersInPartRegion, playerToAdd.Name) then
table.insert(playersInPartRegion, playerToAdd.Name)
end
end)
game.ReplicatedStorage.RemovePlayerFromTable.OnServerEvent:Connect(function(playerToRem)
if table.find(playersInPartRegion, playerToRem.Name) then
local count = 0
for _, index in pairs(playersInPartRegion) do
count = count + 1
if index == playerToRem.Name then
table.remove(playersInPartRegion, count)
break
end
end
end
end)
-- Now You Need to Check if The Players Near the Part / Touching the Part are More than 1.
while wait(5) do
if #playersInPartRegion < 2 and #playersInPartRegion > 0 then
for _, player in pairs(game.Players:GetChildren()) do
if table.find(playersInPartRegion, player.Name) then
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
humanoidRootPart.Position = lobby.Position
end
end
end
end
Intermission script(Credits to The DevKing):
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)