BTW, this script is just part of the main script of a game where a red team goes against a blue team.
I've tried EVERYTHING with this script. Everything works properly, except the winning conditions. For some reason, the Red Team always wins. No matter how many players are on the team or how many players have died, the script just cuts off the round's for loop and makes the winning team red EVERY SINGLE TIME. Does anyone know what i did wrong here? Thank you so much for your time! The script is quite long, so sorry about that. The output just doesnt give me any errors or where it went wrong, so the whereabouts of this erorr in the script is just huge.
PS, BlueDeaths and RedDeaths values are set to 0 by default.
local RedDeaths = game.Workspace.GameScript.DeathMatchMode.Config.RedDeaths
local BlueDeaths = game.Workspace.GameScript.DeathMatchMode.Config.BlueDeaths
local WinningTeam
for i = 150,1,-1 do
if BlueDeaths.Value == #BlueTeamPlayers then
WinningTeam = game.Teams.Red
break
end
if RedDeaths.Value == #RedTeamPlayers then
WinningTeam = game.Teams.Blue
break
end
status.Value = "Time Left: "..i
wait(1)
end
status.Value = "Game End!"
FadeGameTrack()
game.Workspace.GameEffects.RoundEnd:Play()
wait(1)
--Red Team Win Conditions-------------------------------------------------
if WinningTeam == game.Teams.Blue then
status.Value = "The Winner is the Blue Team!"
end
if WinningTeam == game.Teams.Red then
status.Value = "The Winner is the Red Team!"
end
local Players = game:GetService("Players"):GetChildren() --Get all players
for i=1, #Players do --Loop through all players
if Players[i].Team == WinningTeam then --If the player is on the winning team then
Players[i].leaderstats.Money.Value = Players[i].leaderstats.Money.Value + 10 --Reward
end
end
wait(8)

1 comment
If there is nothing wrong with the script then there is a problem with the context. Like there is likely a problem with #RedTeamPlayers. Try simply using #game.Teams.Red:GetPlayers().