I am making it so that if a player leaves while the timer is counting down it would stop. but it would just reset the timer and play it over and over again. I can't figure out a solution to this problem.
ReplicatedStorage = game:GetService("ReplicatedStorage")
Status = ReplicatedStorage:WaitForChild('Status')
Timer = ReplicatedStorage:WaitForChild('Timer')
PRequired = 2
NumPlayers = ReplicatedStorage.Players
if NumPlayers.Value >= PRequired then
print("Players Ready!")
else
Status.Value = 'Must have 2 or more players to play'
Timer.Value = '...'
repeat wait(1) until NumPlayers.Value >= PRequired
print("Players Ready!")
end
--Intermission
local Countdown = 20 -- intermission
print("Countdown incoming!")
repeat wait(1)
Countdown = Countdown - 1
Status.Value = 'Intermission'
Timer.Value = Countdown
if NumPlayers.Value <= PRequired then
Status.Value = 'Timer Paused must have 2 or more players to play.'
Timer.Value = '...'
print("Timer paused")
repeat wait() until NumPlayers.Value >= PRequired
Countdown = 20
Status.Value = 'Intermission'
Timer.Value = Countdown
print("Continued")
end
until Countdown <= 0
PlayerCheck Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlayerCount = ReplicatedStorage.Players
game.Players.PlayerAdded:Connect(function()
PlayerCount.Value = PlayerCount.Value + 1
print(PlayerCount.Value)
end)
game.Players.PlayerRemoving:Connect(function()
PlayerCount.Value = PlayerCount.Value -1
print(PlayerCount.Value)
end)

1 comment
by repeat do you mean it resets to 20 and when it reaches 0 it goes back up to 20 and keeps doing that?