I've been trying to make a minigames script for a while now, but I can't fix all of the errors for the life of me. My most recent error is that if the game goes from having two players to one player during the intermission, it skips it completely and goes into the round. Thanks in advance for finding the error.
--// %Script by cmgtotalyawesome%
--// Variables
MapStorage = workspace.MapStorage
IntermissionTime = 15
Players = game.Players:GetChildren()
_G.RoundInProgress = false
NumPlayers = game.ReplicatedStorage.NumPlayers
NumPlayers.Value = 0
GameTime = 90
game.Players.PlayerAdded:connect(function(plr)
NumPlayers.Value = NumPlayers.Value + 1
end)
game.Players.PlayerRemoving:connect(function(plr)
NumPlayers.Value = NumPlayers.Value - 1
end)
--// Intermission/Gameplay
while wait(1) do
if not _G.RoundInProgress and NumPlayers.Value >= 2 then
for i = IntermissionTime, 0, -1 do
if NumPlayers.Value < 2 then break end
game.ReplicatedStorage.StatusValue.Value = "Intermission: ".. i
wait(1)
end
local maps = game.ServerStorage.Maps:GetChildren()
local chosenmap = maps[math.random(1, #maps)]
local map = game.ServerStorage.Maps[chosenmap.Name]:Clone()
map.Parent = workspace.MapStorage
_G.RoundInProgress = true
for i, v in pairs(game.Players:GetPlayers()) do
local a = v.Name
local player = Instance.new("Model", game.ReplicatedStorage.Players)
player.Name = a
local Spawns = chosenmap.Spawns:GetChildren()
workspace[a].Torso.CFrame = CFrame.new(MapStorage[chosenmap.Name].Spawns[math.random(1, #Spawns)].Position)
if chosenmap.Name == "TeamKnockOff" or chosenmap.Name == "KnockOff" then
windforce = game.ServerStorage.Windforce:Clone()
windforce.Parent = v.Backpack
wait()
end
end
game.ReplicatedStorage.StatusValue.Value = "Round In Progress"
for i = GameTime, 0, -1 do
if _G.RoundInProgress == false then break end
wait(1)
game.ReplicatedStorage.StatusValue.Value = "Round in progress, ".. i.. " seconds left"
end
workspace.MapStorage:ClearAllChildren()
_G.RoundInProgress = false
end
end

1 comment
Instead of using a value in RS to represent the amount of players in a game, just use "#game.Players:GetPlayers()". Before starting the round, check one more time, just in case.