My script rewards the losing team I dont know why can anyone help me?
local AliveBlue = 0
local AliveRed = 0
local WinTeam = nil
if Mode.Value == "Team Deathmatch" then
for i,v in pairs(Players) do
if v:WaitForChild("Team").Value == "Red" then
AliveRed = AliveRed + 1
else
AliveBlue = AliveBlue + 1
end
end
if AliveBlue > AliveRed then
print("Winner BLUE!")
WinTeam = "Blue"
else
print("Winner RED!")
WinTeam = "Red"
end
end
for i=1,5 do
Music.Volume = 1 - ((i*2)/10)
wait(0.1)
end
Music:Stop()
WinMusic.SoundId = id..(Musics.Win[math.random(1,#Musics.Win)])
WinMusic:Play()
local Players = game.Players:GetPlayers()
for i = 1, #Players do
if Mode.Value == "Classic" then
if Players[i].Playing.Value == true then
table.insert(Winners, Players[i].Name)
Players[i].leaderstats.Money.Value = Players[i].leaderstats.Money.Value + 25
Players[i].leaderstats.Wins.Value = Players[i].leaderstats.Wins.Value + 1
Players[i].Character.Humanoid.Health = 0
Players[i].Playing.Value = false
Players[i].PlayerGui.Main.MoneyShower.TextLabel.Visible = true
end
elseif Mode.Value == "Team Deathmatch" then
if Players[i]:FindFirstChild("Team") ~= nil then
if Players[i]:WaitForChild("Team").Value == WinTeam then
table.insert(Winners, Players[i].Name)
Players[i].leaderstats.Money.Value = Players[i].leaderstats.Money.Value + 25
Players[i].leaderstats.Wins.Value = Players[i].leaderstats.Wins.Value + 1
Players[i].Character.Humanoid.Health = 0
Players[i].Playing.Value = false
Players[i].PlayerGui.Main.MoneyShower.TextLabel.Visible = true
end
Players[i]:WaitForChild("Team"):Destroy()
end
end
end
RemoveMap()
ChangeText('GAME OVER!')
State.Value = "Intermission"
wait(4)
end

1 comment
Try to make a team check. So the winner team only will get the reward.