Help adding player minimum and win condition for round script

How do I make it so there has to be 2 players in the game for this intermission to work? and how do I make it so that if there is 1 player left in the match then that player will be given the win?

local s = script.Stat
local vals = game.ReplicatedStorage.vals
local t = 0
local curmap
while true do
t = 25
repeat
t = t-1
s.Value = “Loading Maps . . . “…t
wait(1)
until t == 0
s.Value = “Voting Map”
wait(10)
local mapselect = game.ReplicatedStorage.Games:GetChildren()
local choose = math.random(1,#mapselect)
local curnum = 0
for i =1,#mapselect do
curnum = curnum +1
if curnum == choose then
mapselect[i]:Clone().Parent = workspace
curmap = mapselect[i].Name
s.Value = “”…mapselect[i].Name
end
end
wait(5)
local plrs = game.Players:GetChildren()
for i = 1,#plrs do
local num = math.random(1,32)
plrs[i].Character.Head.CFrame = CFrame.new(workspace.Teleports[“Part”…num].Position)
plrs[i].Character.Parent = workspace.Ingame
end
t=60
repeat
t = t-1
s.Value = t…””
wait(2)
until t ==0 or vals.Winner.Value ~= “”
if vals.Winner.Value ~= “” then
s.Value = vals.Winner.Value… " has won!"
game.Players[vals.Winner.Value].leaderstats.Points.Value =game.Players[vals.Winner.Value].leaderstats.Points.Value +50
game.Players[vals.Winner.Value].leaderstats.Wins.Value = game.Players[vals.Winner.Value].leaderstats.Wins.Value +1
vals.Winner.Value = “”
else
s.Value = “No one has won!”
end
wait(4)
local ingame = workspace.Ingame:GetChildren()
for i =1,#ingame do
local plr = game.Players:GetPlayerFromCharacter(ingame[i])
plr:LoadCharacter()

end
workspace:WaitForChild(curmap):Destroy()

end

Here is a uncopylocked version of the script… please someone figure it out…

1 Like

Hopefully this works!

local s = script.Stat
local vals = game.ReplicatedStorage.vals
t = 0

while true do
   t = 25
   repeat
   repeat s.Value = "Not Enough Players" wait() until game.Players.NumPlayers >= 2
   
   	s.Value = "Intermission" ..10
   	s.Value = "Intermission" ..9
   	s.Value = "Intermission" ..8
   	s.Value = "Intermission" ..7
   	s.Value = "Intermission" ..6
   	s.Value = "Intermission" ..5
   	s.Value = "Intermission" ..4
   	s.Value = "Intermission" ..3
   	s.Value = "Intermission" ..2
   	s.Value = "Intermission" ..1
   	
   	wait(1)
   	t = t-1
   	s.Value = "Loading Maps . . . "..t
   	wait(1)
   	
   until t == 0
   s.Value = "Voting Map"
   wait(10)
   local mapselect = game.ReplicatedStorage.Games:GetChildren()
   local choose = math.random(1,#mapselect)
   curnum = 0
   for i =1,#mapselect do
   	curnum = curnum +1
   	if curnum == choose then
   		mapselect[i]:Clone().Parent = workspace
   		curmap = mapselect[i].Name
   		s.Value = ""..mapselect[i].Name
   	end
   end
   wait(5)
   local plrs = game.Players:GetChildren()
   for i = 1,#plrs do
   	local num = math.random(1,32)
   	plrs[i].Character.Head.CFrame = CFrame.new(workspace.Teleports["Part"..num].Position)
   	plrs[i].Character.Parent = workspace.Ingame
   end
   t=60
   repeat
   	t = t-1
   	s.Value = t..""
   	wait(2)
   until t ==0 or vals.Winner.Value ~= ""
   if vals.Winner.Value ~= "" then
   	s.Value = vals.Winner.Value.. " has won!"
   	game.Players[vals.Winner.Value].leaderstats.Points.Value =game.Players[vals.Winner.Value].leaderstats.Points.Value +50
   	game.Players[vals.Winner.Value].leaderstats.Wins.Value = 	game.Players[vals.Winner.Value].leaderstats.Wins.Value +1
   	vals.Winner.Value = ""
   else
   	s.Value = "No one has won!"
   end
   wait(4)
   local ingame = workspace.Ingame:GetChildren()
   for i =1,#ingame do
   	local plr = game.Players:GetPlayerFromCharacter(ingame[i])
   	plr:LoadCharacter()
   	
   end
   workspace[curmap]:Destroy()
end

repeat wait(1) until #(game.Players:GetPlayers()) >= 2

This line will yield the script until there are 2 or more players in the game (i hope)

Also, instead of using repeat to make countdowns, use for loops, its more clean in my opinion

for i = t, 0, -1 do
    s.Value = "Loading Maps..."..i
    wait(1)
end

For the situation where the player is given the win when said player is the only one in the server (grammar 100), i used to make a roundbased game and this is what i did:

I made a table that keeps track of every player thats in the round (not in lobby or anything), whenever a player deploys, the player is inserted in the table, whenever a player leaves, the player is removed from the table. For removing, i just made it so the script will check what player is in the game and what player is not.

local players = {}

for i,v in pairs(game.Players:GetPlayers()) do
    if v then
        table.insert(players, v)
    end
end

for i = GameTime, 0, -1 do -- my countdown for loop
    s.Value = i -- if you want to display the time, do this
    
    for x,c in pairs(players) do
        if c then
            --epic
        else
            --not epic
            table.remove(players,x)
        end
    end
    if #players == 1 then
        vals.Winner.Value = players[1].Name
        break -- break stops the for loop, assuming you want the round to end immediately
    end
    wait(1)
end
--game ends

I may have missed some things i just woke up. Hope this helped!

1 Like

Do I put this into a new script ?

You must transfer this code into your current script by replacing some certain things, such as the repeat loops being replaced with the for loops. I cant exactly tell you what to replace right now i am braindead. But you should be able to figure it out! I believe in you!