Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I end round on specific kills?

Asked by 2 years ago

I want to make it so when a team gets a specific amount of kills the round ends instead of ending one the timer is over. How would I do it?

local Time = game.ReplicatedStorage.Time
local BlueKill = game.ReplicatedStorage.BlueKill
local RedKill = game.ReplicatedStorage.RedKill
local Status = game.ReplicatedStorage.Status
local Teams = game:GetService("Teams")

local BlueTeam = 0
local RedTeam = 0

function TimeWait(TimeToWait)
    Time.Value = TimeToWait

    repeat
        wait(1)
        Time.Value -= 1
    until Time.Value < 1
end

game.Players.PlayerAdded:Connect(function(player)
    if Status.Value == "Round in progress" then
        if BlueTeam < RedTeam then
            BlueTeam += 1
            player.Team = Teams.Blue
            player.TeamColor = Teams.Blue.TeamColor
        elseif RedTeam < BlueTeam then
            RedTeam += 1
            player.Team = Teams.Red
            player.TeamColor = Teams.Red.TeamColor
        end

        wait(1)
        player:LoadCharacter()
    end

    player.CharacterAdded:Connect(function(character)
        character.Humanoid.Died:Connect(function()
            if character.Humanoid:FindFirstChild("creator") then
                local killer = character.Humanoid:FindFirstChild("creator").Value

                if killer.TeamColor == Teams.Blue.TeamColor then
                    BlueKill.Value += -1
                else
                    RedKill.Value += -1
                end
            end
        end)
    end)
end)

while true do
    BlueTeam = 100
    RedTeam = 100
    RedKill.Value = 100
    BlueKill.Value = 100

    for _,v in pairs(game.Players:GetChildren()) do
        v.Team = Teams.Neutral
        v.TeamColor = Teams.Neutral.TeamColor
    end

    Status.Value = "Intermission"
    TimeWait(20)

    if #game.Players:GetChildren() < 2 then 
        Status.Value = "Waiting for more players..." 
        TimeWait(5)
    else
        Status.Value = "Round In Progress"

        for _,v in pairs(game.Players:GetChildren()) do
            if BlueTeam <= RedTeam then
                BlueTeam += 1
                v.Team = Teams.Blue
                v.TeamColor = Teams.Blue.TeamColor

            elseif RedTeam < BlueTeam then
                RedTeam += 1
                v.Team = Teams.Red
                v.TeamColor = Teams.Red.TeamColor

            end
        end

        TimeWait(20)

        for _,v in pairs(game.Players:GetChildren()) do
            v.Team = Teams.Neutral
            v.TeamColor = Teams.Neutral.TeamColor
        end

        wait(1)

        if BlueKill.Value < RedKill.Value then
            Status.Value = "Blue Win!"

        elseif RedKill.Value < BlueKill.Value then
            Status.Value = "Red Win!"

        else
            Status.Value = "Tie!"
        end

        TimeWait(5)
    end
end
0
I never really operated with teams but I think you can add all of the player's kill in the team and if it >= an amount then the round can end NotThatFamouss 605 — 2y

Answer this question