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)
Well, im not good at scripting but you could try this.
local PlayerCount = 0 local Players = game:GetService("Players") local TimerScript = game.Workspace.Script --your timer script Players.PlayerAdded:Connect(function(player) PlayerCount = PlayerCount + 1 end) Players.PlayerRemoving:Connect(function(player) PlayerCount = PlayerCount - 1 end) if PlayerCount == 1 then TimerScript.Disabled = true else TimerScript.Disabled = false end
please tell me if my script wont work, as im bad at scripting, hope this helps!
On line 36 do
until Countdown <= 0 or NumPlayers.Value <= PRequired