Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i fix this my Script rewards the losing team?

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

0

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

1 answer

Hello, Cyrellejheff!

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].Team.Name == WinTeam then --Compares the player's team name to the winning team
                    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

If this don't works, post a comment here

This discussion is preserved as it was. New answers, comments, and votes are closed.