this is now the THIRD problem i’ve had with this game with no clue how to solve. here i am, once more turning to your help.
here’s the issue: i’m trying to tell if remaining players are on the same team, and if so? the game is ended and the people on that team are winners. if it’s a 1v1 on seperate teams and one player wins, the game isn’t ending!
here’s the entire main script:
-- Services --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
-- Modules --
local RoundModule = require(script.RoundModule)
-- Guis --
local StatusGui = StarterGui:WaitForChild("StatusGui")
-- Variables --
local IntermissionTime = 15
local VotingTime = 10
local RoundTime
local AbleToWin = true
local StatusValue = ReplicatedStorage:WaitForChild("Values"):FindFirstChild("StatusValue")
-- Folders --
local Minigames = ReplicatedStorage:WaitForChild("Minigames"):GetChildren()
local CurrentMinigame = game:GetService("Workspace"):WaitForChild("CurrentMinigame")
local InGameFolder = game:GetService("Workspace"):WaitForChild("InGameFolder")
-- Tables --
local WinnersTable = {}
-- Script --
while true do
IntermissionTime = 15
repeat
IntermissionTime -= 1
StatusValue.Value = "Intermission: "..IntermissionTime
task.wait(1)
until IntermissionTime == 0
print("Starting round.")
StatusValue.Value = "Round starting..."
task.wait(1)
StatusValue.Value = "Round starting.."
task.wait(1)
StatusValue.Value = "Round starting."
task.wait(1)
StatusValue.Value = "Round starting"
local RandomMinigame = math.random(1, #Minigames)
local ChosenMinigame = Minigames[RandomMinigame]:Clone()
ChosenMinigame.Parent = CurrentMinigame
local Players = game:GetService("Players"):GetChildren()
for i = 1, #Players do
if Players[i].Character ~= nil then
if ChosenMinigame:FindFirstChild("SwordFight") then
-- Add Teams
local Teams = game:GetService("Teams")
local BlueTeam = Instance.new("Team", Teams)
BlueTeam.Name = "Blue"
BlueTeam.TeamColor = BrickColor.new("Bright blue")
local RedTeam = Instance.new("Team", Teams)
RedTeam.Name = "Red"
RedTeam.TeamColor = BrickColor.new("Really red")
local RandomNum = math.random(1, 2)
local SelectedTeam
if RandomNum == 1 then
SelectedTeam = "Blue"
else
SelectedTeam = "Red"
end
Players[i].Team = Teams:FindFirstChild(SelectedTeam)
-- Spawn Player.
if Players[i].Team == "Blue" then
Players[i].Character.Head.CFrame = ChosenMinigame.BlueBase.BlueSpawn.CFrame
else
Players[i].Character.Head.CFrame = ChosenMinigame.RedBase.RedSpawn.CFrame
end
local Sword = game:GetService("ServerStorage"):FindFirstChild("ClassicSword"):Clone()
Sword.Parent = Players[i].Backpack
Players[i].Character.Parent = InGameFolder
else
-- Normal Spawn.
local RandomTeleportPoint = math.random(1, #ChosenMinigame:WaitForChild("TeleportPoints"):GetChildren())
Players[i].Character.Head.CFrame = ChosenMinigame.TeleportPoints[RandomTeleportPoint].CFrame
Players[i].Character.Parent = InGameFolder
end
end
end
AbleToWin = true
if ChosenMinigame:FindFirstChild("ObstacleRace") then
-- Set up Minigame.
RoundTime = 10
-- Minigame Over.
ChosenMinigame:WaitForChild("EndPoint").Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
if AbleToWin == true then
AbleToWin = false
local Winner = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
table.insert(WinnersTable, Winner.Name)
print("Touched.")
end
end
end)
end
if ChosenMinigame:FindFirstChild("Maze") then
-- Set up Minigame.
RoundTime = 60
RoundModule.LockFirstPerson()
game:GetService("Lighting").ClockTime = 0
-- Minigame Over.
ChosenMinigame:WaitForChild("EndPoint").Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
if AbleToWin == true then
local Winner = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
if table.find(WinnersTable, Winner.Name) then
print("Already won.")
else
table.insert(WinnersTable, Winner.Name)
print("Touched.")
Winner.Character:MoveTo(ChosenMinigame:FindFirstChild("WinnerTeleport").Position)
Winner.Character.Parent = game:GetService("Workspace")
end
end
end
end)
end
if ChosenMinigame:FindFirstChild("SwordFight") then
-- Set up Minigame.
RoundTime = 60
AbleToWin = true
while task.wait() do
local TeamColor1 = game.Players:GetPlayers()[1].TeamColor
local IsSameTeam = true
for i, Player in pairs(game:GetService("Players"):GetPlayers()) do
if Player.Character.Parent == InGameFolder then
if i == 1 then
TeamColor1 = Player.TeamColor
end
if Player.TeamColor ~= TeamColor1 then
IsSameTeam = false
break
end
end
end
if IsSameTeam then
AbleToWin = false
for i, Player in pairs(InGameFolder:GetChildren()) do
if table.find(WinnersTable, Player.Name) then
-- Skip.
else
table.insert(WinnersTable, Player.Name)
end
end
end
end
end
repeat
RoundTime -= 1
StatusValue.Value = "Round over in: "..RoundTime
task.wait(1)
until RoundTime == 0 or AbleToWin == false or #InGameFolder:GetChildren() == 0
AbleToWin = false
RoundModule.UnlockFirstPerson()
game:GetService("Lighting").ClockTime = 14.5
StatusValue.Value = "Round over!"
task.wait(3)
StatusValue.Value = "Winners: "..table.concat(WinnersTable)
for i, Player in pairs(game:GetService("Players"):GetPlayers()) do
if table.find(WinnersTable, Player.Name) then
Player:WaitForChild("leaderstats").Wins.Value += 1
end
end
RoundModule.NewRound()
WinnersTable = {}
task.wait(3)
end
here’s the most crucial points including this problem:
local RandomMinigame = math.random(1, #Minigames)
local ChosenMinigame = Minigames[RandomMinigame]:Clone()
ChosenMinigame.Parent = CurrentMinigame
local Players = game:GetService("Players"):GetChildren()
for i = 1, #Players do
if Players[i].Character ~= nil then
if ChosenMinigame:FindFirstChild("SwordFight") then
-- Add Teams
local Teams = game:GetService("Teams")
local BlueTeam = Instance.new("Team", Teams)
BlueTeam.Name = "Blue"
BlueTeam.TeamColor = BrickColor.new("Bright blue")
local RedTeam = Instance.new("Team", Teams)
RedTeam.Name = "Red"
RedTeam.TeamColor = BrickColor.new("Really red")
local RandomNum = math.random(1, 2)
local SelectedTeam
if RandomNum == 1 then
SelectedTeam = "Blue"
else
SelectedTeam = "Red"
end
Players[i].Team = Teams:FindFirstChild(SelectedTeam)
-- Spawn Player.
if Players[i].Team == "Blue" then
Players[i].Character.Head.CFrame = ChosenMinigame.BlueBase.BlueSpawn.CFrame
else
Players[i].Character.Head.CFrame = ChosenMinigame.RedBase.RedSpawn.CFrame
end
local Sword = game:GetService("ServerStorage"):FindFirstChild("ClassicSword"):Clone()
Sword.Parent = Players[i].Backpack
Players[i].Character.Parent = InGameFolder
else
-- Normal Spawn.
local RandomTeleportPoint = math.random(1, #ChosenMinigame:WaitForChild("TeleportPoints"):GetChildren())
Players[i].Character.Head.CFrame = ChosenMinigame.TeleportPoints[RandomTeleportPoint].CFrame
Players[i].Character.Parent = InGameFolder
end
end
end
if ChosenMinigame:FindFirstChild("SwordFight") then
-- Set up Minigame.
RoundTime = 60
AbleToWin = true
while task.wait() do
local TeamColor1 = game.Players:GetPlayers()[1].TeamColor
local IsSameTeam = true
for i, Player in pairs(game:GetService("Players"):GetPlayers()) do
if Player.Character.Parent == InGameFolder then
if i == 1 then
TeamColor1 = Player.TeamColor
end
if Player.TeamColor ~= TeamColor1 then
IsSameTeam = false
break
end
end
end
if IsSameTeam then
AbleToWin = false
for i, Player in pairs(InGameFolder:GetChildren()) do
if table.find(WinnersTable, Player.Name) then
-- Skip.
else
table.insert(WinnersTable, Player.Name)
end
end
end
end
end
repeat
RoundTime -= 1
StatusValue.Value = "Round over in: "..RoundTime
task.wait(1)
until RoundTime == 0 or AbleToWin == false or #InGameFolder:GetChildren() == 0
AbleToWin = false
RoundModule.UnlockFirstPerson()
game:GetService("Lighting").ClockTime = 14.5
StatusValue.Value = "Round over!"
task.wait(3)
StatusValue.Value = "Winners: "..table.concat(WinnersTable)
for i, Player in pairs(game:GetService("Players"):GetPlayers()) do
if table.find(WinnersTable, Player.Name) then
Player:WaitForChild("leaderstats").Wins.Value += 1
end
end
RoundModule.NewRound()
WinnersTable = {}
task.wait(3)
end
any help on this would be highly appreciated!