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)
To debug, you should add print
statements to display values that don't seem to be working correctly. This will give you insight into what's going right/wrong. If you're testing with friends online, you can press F9 for the developer console. For instance, you might print after line 8:
print("Blue won", BlueDeaths.Value, #BlueTeamPlayers, RedDeaths.Value, #RedTeamPlayers)
and the same thing for Red, but with "Red won".
For example, say it printed out "Blue won" - then you'd know there's a problem with the second half of your script. More likely it will say "Red won" (unless the game times out), but at least you'll get to see all the numbers and get a clue as to what's going on. For example, maybe - despite both teams losing 1 player (with a team of size 2), it says Red won 2 2 0 2
, which would indicate that, though it has the correct size of each team, the death counters are incrementing BlueDeaths regardless of what team the player is on.
Looking at what you've provided, I can see these potential problems: